Initial Rails Setup: All DB tasks fail


#1

Hi,

I am attempting to start a Rails 5.1 app from scratch using ROM. I have defined a users relation, but no corresponding migration (yet). When I try to run rails db:create_migration[create_users] task, I get:

[Users] failed to infer schema. Make sure tables exist before ROM container is set up. This may also happen when your migration tasks load ROM container, which is not needed for migrations as only the connection is required (PG::UndefinedTable: ERROR:  relation "users" does not exist
LINE 1: ..."."attnum" > 0) AND ("pg_class"."oid" = CAST(CAST('"users"' ...
                                                             ^
)
/app/db/schema.rb doesn't exist yet. Run `rails db:migrate` to create it, then try again. If you do not intend to use a database, you should instead alter /app/config/application.rb to limit the frameworks that will be loaded.

But, I can’t seem to figure out how to get that file created, as any rake task I run gives this error. I am sure I am just being dense, so if anyone could nudge me along on getting a simple relation, schema, migration in “the right way”, I’d appreciate it.

Thanks,
Glenn


#2

FWIW, if I do a rails db:schema:dump, I get the schema.rb file and can create migrations, but if I run rails db:migrate, I get this:

You have 1 pending migration:
  20170719165832 EnableUuid
Run `rails db:migrate` to update your database then try again.

The schema_migrations table has one entry (0) from I don’t know where (presumably the schema:dump task) and no amount of removing it, etc. makes the migration run.


#3

Relations are automatically registered so it will blow up if there’s no corresponding table.


#4

OK, and I am trying to create the table with a migration, but it just says it’s pending and to run rails db:migrate, which I do, and it says it’s pending and to run rails db:migrate

Am I meant to create all tables before their corresponding relations?