أظن أن هذه مشكلة أخرى في جدول تالف؟ مع ذلك، يحدث هذا في حالة من غير المرجح أن يكون قاعدة البيانات قد أُغلقت بشكل غير سليم.
لقد قمت بإنشاء وحذف شارة بدون أعضاء، وعمل ذلك بشكل صحيح. ثم أضفت مستخدمًا إلى شارة جديدة وحذفتها، وعمل ذلك بشكل صحيح أيضًا.
Started DELETE "/admin/badges/118" for 71.89.242.121 at 2020-05-28 16:50:04 +0000
Processing by Admin::BadgesController#destroy as */*
Parameters: {"id"=>"118"}
Rendering text template
Rendered text template (Duration: 0.0ms | Allocations: 1)
Completed 500 Internal Server Error in 304ms (ActiveRecord: 0.0ms | Allocations: 114838)
ActiveRecord::InvalidForeignKey (PG::ForeignKeyViolation: ERROR: update or delete on table "badges" violates foreign key constraint "fk_rails_38ea484ed4" on table "user_profiles"
DETAIL: Key (id)=(118) is still referenced from table "user_profiles".
)
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-mini-profiler-2.0.1/lib/patches/db/pg.rb:72:in `exec_params'
Failed to handle exception in exception app middleware : PG::ForeignKeyViolation: ERROR: update or delete on table "badges" violates foreign key constraint "fk_rails_38ea484ed4" on table "user_profiles"
DETAIL: Key (id)=(118) is still referenced from table "user_profiles".
لكنني لا أعرف تمامًا أين أبحث أو أي فهرس يجب أن أحاول إعادة بنائه.
لا. يبدو أن هناك خللاً (ثانوياً) في إمكانية بدء حذف شارة إذا كان شخص ما يمتلكها. سيكون من الأفضل لو أن واجهة المستخدم تمنع ذلك. من الصحيح تماماً أن قاعدة البيانات تمنع الحذف وتحافظ على سلامة العلاقات المرجعية.