I want to delete something from my database. The value refers to some other tables.
Error:
Mysql2::Error: Cannot delete or update a parent row: a foreign key constraint fails
How can I resolve this correctly?
If I add some restrictions, for example, for the delete cascade, other values will not be deleted correctly?
Edit:
def delete
@vid = Movie.find params[:id]
@vid.delete
redirect_to :action => :add
end
Update Models
movie.rb
class Movie < ActiveRecord::Base
has_many :comments, :dependent => :destroy
has_many :ratings
belongs_to :channel
has_and_belongs_to_many :tags
has_and_belongs_to_many :categories
mount_uploader :video, MovieUploader
comment.rb
class Comment < ActiveRecord::Base
belongs_to :movie
belongs_to :user
belongs_to :rating
Felix source
share