rails still looking for old foreign key after removing a model

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

rails still looking for old foreign key after removing a model

fugee ohu
I had a Profile model that everything else belonged to and Profile in turn belonged to user The idea was that a user could have multiple accounts/identifies/personas whatever you wanna call them because people do it anyway with separate accounts At some point I decided I don't really wanna do that so I took out the Profile model Now when I try to create a new Post rails complains that user_id references profiles_id but I can't find where rails is getting the foreign key from Is it a temporary file I have to delete? Thanks in advance

ActiveRecord::InvalidForeignKey (Mysql2::Error: Cannot add or update a child row: a foreign key constraint fails (`socialnetworking_development`.`posts`, CONSTRAINT `fk_rails_cd61a4aa45` FOREIGN KEY (`user_id`) REFERENCES `profiles` (`id`)): 

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/838cf725-555f-4715-80bc-e8b48130ca93%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: rails still looking for old foreign key after removing a model

Hassan Schroeder-2
On Sat, Jun 10, 2017 at 6:50 PM, fugee ohu <[hidden email]> wrote:

> ... so I took out the Profile model

What does "took out" mean? What exactly did you do? Is it the
exact reverse of how you created that model to start with?

> ActiveRecord::InvalidForeignKey (Mysql2::Error: Cannot add or update a child
> row: a foreign key constraint fails (`socialnetworking_development`.`posts`,
> CONSTRAINT `fk_rails_cd61a4aa45` FOREIGN KEY (`user_id`) REFERENCES
> `profiles` (`id`)):

Given that you're seeing a *database-generated* error -- have you
looked at the relationships, i.e. foreign keys, in the referenced tables
in that database?

--
Hassan Schroeder ------------------------ [hidden email]
twitter: @hassan
Consulting Availability : Silicon Valley or remote

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CACmC4yD%3DEiUEO%3D%2B%3DtwA6a1RiTGdEWR7oZQMWX5ozepSQx%3D_rvg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.