postgres: Inappropiate migration generated for 'default: null'
See original GitHub issueIssue type:
[x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[x] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[ ] latest
[ ] @next
[x] 0.2.28
Steps to reproduce or a small repository showing the problem:
This issue appears very similar to https://github.com/typeorm/typeorm/issues/5509 but for postgres.
Minimal entity declaration:
import { Entity, Column, PrimaryGeneratedColumn } from "typeorm";
@Entity()
export class Foo {
@PrimaryGeneratedColumn()
id: number;
@Column()
requiredString: string;
@Column({ type: "text", nullable: true })
optionalString: string | null;
@Column({ type: "text", nullable: true, default: null })
optionalStringWithExplicitDefault: string | null;
}
Even after syncing the schema, generating a migration still results in the lines
// from `up` method
await queryRunner.query(`ALTER TABLE "foo" ALTER COLUMN "optionalstringwithexplicitdefault" SET DEFAULT null`);
// in `down` method
await queryRunner.query(`ALTER TABLE "foo" ALTER COLUMN "optionalstringwithexplicitdefault" DROP DEFAULT`);
Expected behavior: the migration should not include these lines.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to declare a nullable enum by default null in postgreSQL ...
I'm new on Knex, and I have to resolve a migration that adds a column with a value of type enum which should...
Read more >Documentation: 15: ALTER TABLE - PostgreSQL
The new default value will only apply in subsequent INSERT or UPDATE commands; it does not cause rows already in the table to...
Read more >Avoid SET/DROP DEFAULT unless a field changes from null ...
Migration forces "DROP DEFAULT" SQL → Avoid SET/DROP DEFAULT on field alteration if not required. Triage Stage: Unreviewed → Accepted. Type: ...
Read more >Troubleshooting migration tasks in AWS Database Migration ...
The error "Relation 'awsdms_apply_exceptions' already exists" often occurs when a Redshift endpoint is specified as a PostgreSQL endpoint. To fix this issue, ...
Read more >The Complete Oracle to Postgres Migration Guide - EDB
Learn everything about migrating from Oracle to Postgres, ... GENERATED BY DEFAULT allows the user the option to insert or update a value ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@brahn I have the same issue. Looking at https://github.com/typeorm/typeorm/issues/150#issuecomment-272158658 , it appears as a temporary workaround we can do
Let me know if this works for you
To be more specific, when you generate multiple new migrations, each time the case of
null
gets flipped.For example, at first it will say
then after I run that migration, and gen a new one, the next migration will say
After you run the next migration, generating yet another migration produces
I don’t think @brahn noticed this when writing the issue.
This certainly seems like a TypeORM bug. Please let me know what I can do to help resolve it