Rails: PG::UndefinedTable: ERROR: relation “…” does not exist

So the issue is happening because CreateOrganizations migration is being run before CreateActioncodes is executed.

CreateActioncodes is to be run first thereby ensuring that the action codes table exists.

The order in which migrations are run is based on the time stamp of the migration – as indicated in the name of the file. 20141014183645_create_users.rb will run before 20141014205756_add_index_to_users_email.rb as the timestamp of the second one – 20141014205756 is after that of the first one – 20141014183645.

Make sure the time-stamps of the CreateOrganizations migration is after that of CreateActioncodes migration.

Either you could manually change the timestamp in the file names. Or delete these migration files, and create them in the correct order.

Leave a Comment