Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration fails but query runs in pgadmin #894

Open
redeemefy opened this issue Jun 9, 2022 · 0 comments
Open

Migration fails but query runs in pgadmin #894

redeemefy opened this issue Jun 9, 2022 · 0 comments

Comments

@redeemefy
Copy link

redeemefy commented Jun 9, 2022

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.
Screen Shot 2022-06-09 at 11 26 02 AM

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant