This simple test code:
return queryInterface.createTable('tadam', {id: Sequelize.INTEGER, humus: Sequelize.STRING(255)})
.then(queryInterface.sequelize.query('ALTER TABLE tadam ADD PRIMARY KEY (id)'));
returns the following error:
Unhandled rejection SequelizeDatabaseError: relation "tadam" does not exist
Now, I understand that by the time the second promise (about altering the table) is executed, the table hasn't been created yet.
It could not be because all queries within the migration are executed together at once, because I have, f.e. this test migration:
return queryInterface.sequelize.query('ALTER TABLE tadam DROP CONSTRAINT tadam_pkey')
.then(queryInterface.removeIndex('tadam', 'tadam_pkey'));
and it works fine.
So, can anyone give explanation why the first one does not work and how can I implement it, so that the creation of the table + adding the PK can be executed from a single migration?