-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Update to 0.2.5 breaking things #2108
Comments
I recently updated from 0.2.0-alpha.27 to 0.2.5 and suddenly everything is breaking. its hard to reproduce the code but I can give an example:
This was working fine as the server started but now after the update it gives me I then added a default value
Then it tells me that the name test is duplicated and
Any idea on why this is suddenly happening? |
its a primary column and primary columns are not allowed to have duplicated values, so please check your data. |
Why doesn't that error show up in the older versions then? And it drops it right before adding it again.
|
don't know, maybe there was a bug and something was working wrong in previous versions
correct. primary columns are required to be dropped to make some changes on them. |
Got it, thanks. |
Not sure if I should be opening a new issue or ask to reopen this one, I'm encountering the same behavior. import { Entity, Column, PrimaryGeneratedColumn, BaseEntity } from 'typeorm';
import * as slug from 'slug';
@Entity()
export class SkillTagEntity extends BaseEntity {
@PrimaryGeneratedColumn('uuid')
public id: string;
@Column('varchar', { unique: true })
public slug: string;
@Column('varchar')
private name: string;
@Column('timestamp', { nullable: true })
public deleteDate?: Date;
} The error :
Thing is, I have no null value in the column "slug", not do I have duplicates.
Seems to me that the combo Edit : it seems that it's trying to add the column instead of altering it ? But the error does not concur |
@RDeluxe I had the same error popping up when the data in the tables looked perfect. Your comment about the query actually trying to create the column helped me find the issue. Do you have |
Please re-open the issue, because it seems that the devs here don't take this issue serious. I am having the same problem with @Alain1405 @RDeluxe. |
Same problem here. |
To solve this issue, delete the entire dist folder and try again. Hopefully it works for you as well. Let us know if this did the trick. |
I was having the same problem, I noticed that in PGAdmin the fields that gave this error were with the type "VARING CHARACTER" without the length. Ex: I had a field in my Entity called crp which is of the string type which is six characters, but in the Database it was only "CHARACTER VARYING" I changed it to "CHARACTER VARYING (6)" and it worked, I hope it helps someone :D |
I'm having a similar issue when trying to change the type of a column. Here's the migration that creates the table originally: import { MigrationInterface, QueryRunner, Table } from "typeorm";
export class CreateClient1644456282318 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: "client",
columns: [
{
name: "id",
type: "uuid",
default: "uuid_generate_v4()",
isPrimary: true,
},
{
name: "name",
type: "varchar",
length: "100",
},
{
name: "created_at",
type: "timestamptz",
default: "now()",
},
],
}),
true
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable("client");
}
} Here's the migration that alters the column type: import { MigrationInterface, QueryRunner, TableColumn } from "typeorm";
export class ChangeClientNameColumnType1644540433176
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.changeColumn(
"client",
"name",
new TableColumn({
name: "name",
type: "text",
})
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.changeColumn(
"client",
"name",
new TableColumn({
name: "name",
type: "varchar",
length: "100",
})
);
}
} When I run start my app in production, it crashes on this migration: yarn run v1.22.17
--
$ node ./dist/index.js
Using prod connection options
3 migrations are already loaded in the database.
4 migrations were found in the source code.
CreateToken1644456290388 is the last executed migration. It was executed on Thu Feb 10 2022 01:24:50 GMT+0000 (Coordinated Universal Time).
1 migrations are new migrations that needs to be executed.
Migration "ChangeClientNameColumnType1644540433176" has been failed, error: column "name" of relation "client" contains null values
/public-api/node_modules/typeorm/error/TypeORMError.js:9
var _this = _super.call(this, message) \|\| this;
^
QueryFailedError: column "name" of relation "client" contains null values
at QueryFailedError.TypeORMError [as constructor] (/public-api/node_modules/typeorm/error/TypeORMError.js:9:28)
at new QueryFailedError (/public-api/node_modules/typeorm/error/QueryFailedError.js:13:28)
at PostgresQueryRunner.<anonymous> (/public-api/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:250:31)
at step (/public-api/node_modules/tslib/tslib.js:143:27)
at Object.throw (/public-api/node_modules/tslib/tslib.js:124:57)
at rejected (/public-api/node_modules/tslib/tslib.js:115:69)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
query: 'ALTER TABLE "client" ADD "name" text NOT NULL',
parameters: undefined,
driverError: error: column "name" of relation "client" contains null values
at Parser.parseErrorMessage (/public-api/node_modules/pg-protocol/dist/parser.js:287:98)
at Parser.handlePacket (/public-api/node_modules/pg-protocol/dist/parser.js:126:29)
at Parser.parse (/public-api/node_modules/pg-protocol/dist/parser.js:39:38)
at Socket.<anonymous> (/public-api/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (node:events:520:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Socket.Readable.push (node:internal/streams/readable:228:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
length: 140,
severity: 'ERROR',
code: '23502',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: 'public',
table: 'client',
column: 'name',
dataType: undefined,
constraint: undefined,
file: 'tablecmds.c',
line: '5454',
routine: 'ATRewriteTable'
},
length: 140,
severity: 'ERROR',
code: '23502',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: 'public',
table: 'client',
column: 'name',
dataType: undefined,
constraint: undefined,
file: 'tablecmds.c',
line: '5454',
routine: 'ATRewriteTable'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. I checked the database, and the client.name column does NOT contain any null values... This is not caused by import { ConnectionOptions, createConnection } from "typeorm";
const baseConnOpts: ConnectionOptions = {
type: "postgres",
port: 5432,
entities: [__dirname + "/entity/**/*.js"],
migrations: [__dirname + "/migrations/**/*.js"],
migrationsRun: true,
synchronize: false,
logging: ["schema"],
logger: "simple-console",
};
// ...
const prodConnOpts: ConnectionOptions = {
...baseConnOpts,
...{
host: process.env.DB_HOST,
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
},
};
function getConnOpts() {
if (process.env.ENV == "prod") {
console.log("Using prod connection options");
return prodConnOpts;
} else {
console.log("Using dev connection options");
return devConnOpts;
}
}
export function getConnection() {
return createConnection(getConnOpts());
} |
I had this issue and it can be fixed indeed as the community mentioned by setting |
I had the same bug, when I was going to add a column in the "user" table the solution was to warn that initially the column will be null, unfortunately I could not add a fixed value when creating it, as it generated some errors. Here's the example that worked for me:
|
What's up with this issue now? it's still happening.
I tried doing this in the category.entity class:
It auto updated all |
Giving
Now I keep the |
Issue type:
[X ] question
[ ] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ]
cordova
[ ]
mongodb
[ ]
mssql
[ ]
mysql
/mariadb
[ ]
oracle
[X ]
postgres
[ ]
sqlite
[ ]
sqljs
[ ]
react-native
TypeORM version:
[ X]
latest
[ ]
@next
[ ]
0.x.x
(or put your version here)Steps to reproduce or a small repository showing the problem:
The text was updated successfully, but these errors were encountered: