— sql, postgresql, code snippet, today-i-learned — 1 min read
I've always been weak with database stuff, but I'm pretty happy that today I solved a few rookie-level stuff on my own!
This was simply due to the tiny error in the model definition of the table. My mistake was I use a pluralized name in the migration
file but singularized version in the model
definition file instead.
1{2 tableName: 'JohnDoes',3 sequelize: db,4}
1up: (queryInterface, Sequelize) => queryInterface.createTable('JohnDoes', {
I realized that my table structure was a bit off, and deleting the sequelize meta didn't help to initiate the migration anew. :(
Ran into an error abt the default value:
Postgres: Default for column cannot be cast automatically to type enum
(highlighted)
1-- rename the old enum2alter type "my_enum" rename to "my_enum__";34-- create the new enum5create type "my_enum" as enum ('value1', 'value2', 'value3');67-- alter all your enum columns8alter table "my_table" alter my_column drop default;9alter table "my_table"10 alter column my_column type "my_enum" using my_column::text::"my_enum";1112-- drop the old enum13drop type "my_enum__";