Reputation: 245
I'm working through the Rails Crash Course book, and the project is to create a social tumblr style clone. I've created a User model with just a name and id (and already migrated), and now I'm trying to implement the following/subscription style that tumblr does. The book has the following to create a new model and migration:
bin/rails g model Subscription leader:references follower:references
The thought is the leader will the the person followed, and the follower is obviously the follower. Both will reference the id from the User table though.
The problem is with the migration. I get the following:
PG::UndefinedTable: ERROR: relation "leaders" does not exist
: ALTER TABLE "subscriptions" ADD CONSTRAINT "fk_rails_7b4891a3a6"
FOREIGN KEY ("leader_id")
REFERENCES "leaders" ("id")
Plus a bunch of other stuff that looks almost exactly the same.
While I'm assuming that it's throwing an error because no leader table with it's own id exists, is there a way to fix the migration to reference the user.id for each reference, or will I just manually need to create each column?
Upvotes: 2
Views: 182
Reputation: 2803
I think it's a Postgres specific problem. You can bypass it by using:
bin/rails g model Subscription leader_id:integer:index follower_id:integer:index
Upvotes: 1