node-pg-migrate
node-pg-migrate copied to clipboard
Migration fails but query runs in pgadmin
I have a migration for adding one column and altering another. The migrations is erroing out with the following error
Error executing:
ALTER TABLE "users"
ADD "contract_id" varchar(255);
error: relation "users" does not exist
However, if I take the SQL script and run it in the pgadmin SQL tool it runs, deleting the column before of course.
ALTER TABLE "users"
ADD "contract_id" varchar(255); -- this column was added in an old migration
It seems that is trying to run an old migration since in the new migration I'm not trying to add contract_id
at all. Here is the new migration
/* eslint-disable camelcase */
exports.shorthands = undefined;
const table = 'business_profile'
exports.up = pgm => {
pgm.addColumn(table, { order_online_call_to_action_type: { type: 'varchar(255)' } }),
pgm.alterColumn(table, 'business_description', { type: 'text' })
};
exports.down = pgm => {
pgm.dropColumn(table, 'order_online_call_to_action_type', { ifExists: true })
pgm.alterColumn(table, 'business_description', { type: 'varchar(255)' })
};
UPDATE
I removed the new migration and ran the command again, and is trying to run all migrations even though they ran already and they have timestamps in the database.
I'm expecting to see
$ npm run migrate up
No migrations to run!
Migrations complete!
UPDATE
There are total of three migration files in the folder, two old and the new migration I'm workin on. I removed those two files out of the folder and left just the new migration, then ran the command again and this is what I get.
node-pg-migrate "up"
> Migrating files:
> - 1654693101519_order-online-column
### MIGRATION 1654693101519_order-online-column (UP) ###
ALTER TABLE "business_profile"
ADD "order_online_call_to_action_type" varchar(255);
ALTER TABLE "business_profile"
ALTER "business_description" SET DATA TYPE text;
INSERT INTO "public"."pgmigrations" (name, run_on) VALUES ('1654693101519_order-online-column', NOW());
Error executing:
ALTER TABLE "business_profile"
ADD "order_online_call_to_action_type" varchar(255);
error: relation "business_profile" does not exist
Why it can't see the table business_profile
. Older migrations have alter this table without errors.