-1

I have a Ruby on Rails app and I want to deploy it on Heroku. Some errors appear and I think it is because the scaffolding order.

By that, I mean that a class named submissions is first created, but this class references another class named Users that is yet to be created.

This is the error that appears when doing rake db:migrate http://pastebin.com/R83a3rsN

And those are the migrate files and their filename

I guess you mean that:

http://pastebin.com/ig5nHjsj for 20160503205437_create_submissions

and

http://pastebin.com/q2jABiep for 20160428101834_create_users

avm_69
  • 183
  • 2
  • 11

3 Answers3

2

You have a member in your db/migrate folder named...

20160424205437_create_submissions.db

Just rename it to

20160503205437_create_submissions.db

that will move it to the bottom of the list of migrations and it'll be executed last.

SteveTurczyn
  • 36,057
  • 6
  • 41
  • 53
  • Already done that and it keeps failing. In fact, create_submissions.db was in fact down the create_users.db, so it was correct. – avm_69 May 03 '16 at 22:09
0

This doesn't seem like a scaffold error per se. Rather, it's an issue with migrations (which scaffolds happened to generate).

To repairs the issue, I'd probably just make a fresh migration which includes all columns your application needs at this point in time. Then edit the order of the create_table blocks to resolve your error.

Then you'd be able to delete the other migration files and run dB:create or reset.

max pleaner
  • 26,189
  • 9
  • 66
  • 118
  • The order of create_table blocks is supposed to be ok: http://pastebin.com/BYumTieQ This is schema.db I have also done an heroku pg:reset DATABASE_URL which works but when I run heroku run rake db:migrate the same error shows: http://pastebin.com/warU3WDE – avm_69 May 03 '16 at 22:08
  • Are you sure you're understanding the schema correctly? You should probably delete your schema before you reset the database. The schema is generated when you run the migrations. – max pleaner May 03 '16 at 23:18
0

This is an issue with cross-dependencies in your migration. In this case, the Submissions table is expecting that the Users table already exist in order to declare a foreign key to it.

Consider declaring the Users table above the Submissions table in your migration.

Michael Gaskill
  • 7,913
  • 10
  • 38
  • 43
  • Already done that and not working. This is my schema.db which is the file I suppose you are talking about: pastebin.com/BYumTieQ – avm_69 May 03 '16 at 22:08
  • Editing your schema.db file won't make a difference. Your migrations are out of order, however you have defined them. Can you include in your original question the filename and contents of the migration file containing the Users table and the migration file containing the Submissions table? Both filename and contents are important to solve this. – Michael Gaskill May 03 '16 at 22:13
  • I guess you mean that: http://pastebin.com/ig5nHjsj for 20160503205437_create_submissions and http://pastebin.com/q2jABiep for 20160428101834_create_users – avm_69 May 03 '16 at 22:16