typeorm: QueryFailedError: column contains null values [SOLVED]
Issue type:
[ ] question [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:
[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)
Steps to reproduce or a small repository showing the problem:
When setting the typeOrmConfig options to synchronize: true instead of synchronize: false, I get to see this error popping up:
QueryFailedError: column “account” contains null values
Does it has anything to do with the column count? I have multiple tables and entity classes and the only table that has 7 columns, is nagging about this issue. Below, I will paste down all the necessary code for you to review. Please fix this bug.
export const typeOrmConfig: TypeOrmModuleOptions = {
type: 'postgres',
host: 'localhost',
port: 5432,
username: 'postgres',
password: 'postgres',
database: 'omega',
entities: [__dirname + '/../**/*.entity.ts', __dirname + '/../**/*.entity.js'],
synchronize: true
}
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, Unique } from "typeorm";
@Entity()
@Unique( [ 'account' ] )
export class HDWallet extends BaseEntity {
@PrimaryGeneratedColumn()
id: number;
@Column()
mnemonic: string;
@Column()
seed: string;
@Column()
publicKey: string;
@Column()
privateKey: string;
@Column()
chainCode: string;
@Column()
account: number;
}
Error message:
[Nest] 10292 - 07/29/2019, 4:37 PM [ExceptionHandler] column "account" contains null values +1ms
QueryFailedError: column "account" contains null values
at new QueryFailedError (/Users/omega/Development/crypto-wallet-api/node_modules/typeorm/error/QueryFailedError.js:11:28)
at Query.callback (/Users/omega/Development/crypto-wallet-api/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:176:38)
at Query.handleError (/Users/omega/Development/crypto-wallet-api/node_modules/pg/lib/query.js:142:17)
at Connection.connectedErrorMessageHandler (/Users/omega/Development/crypto-wallet-api/node_modules/pg/lib/client.js:211:17)
at Connection.emit (events.js:200:13)
at Socket.<anonymous> (/Users/omega/Development/crypto-wallet-api/node_modules/pg/lib/connection.js:126:12)
at Socket.emit (events.js:200:13)
at addChunk (_stream_readable.js:294:12)
at readableAddChunk (_stream_readable.js:275:11)
at Socket.Readable.push (_stream_readable.js:210:10)
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 7
- Comments: 29 (2 by maintainers)
@Tolga-FNT Have you tried completely clearing out your destination folder for tsc? I noticed in my project that there where left over entities from when i changed file names ect, these entities where producing a error similar to the one you described.
try setting synchronize to false
Adding
synchronize: falsedoesn’t “fix” anything, it just prevents TypeORM from making the database schema match the configured entities. Obviously in production it should be set to false because you wouldn’t want any data to be lost, but whatever problems you are encountering need to be fixed another way first, otherwise you may end up with undefined behavior.The original problem described in this issue was about
nullvalues being stored in columns that were missingnullable: true. If you have a separate problem it’s probably best to open a new issue or ask around on the community Slack.Actually, that what @SamuelColacchia suggested did fix the issue. Your answer is in another direction my friend, because I know what I am doing.
It is the directory listed in
compilerOptions->outDirproperty oftsconfig.jsonfile.YEs, but then you need to write migrations, but in my practice, during development it is faster and easy to use sync: true
Im having the same annoying problem with my app .i just set synchronize : false .works fine now
I often faced this issue when developing, you should just delete
distfolder and restart application. It’s working well.for me i make a table for manytomany relation so typeorm try first create a table from regualr
then again from entitiy
so just adding
synchronize:falseto the entity like above fix itSame issue here, had to change synchronize to false, after restarting the application due to file changes it would throw "[Nest] 101380 - 02/05/2020, 21:41:26 [ExceptionHandler] column “userId” contains null values +1ms
QueryFailedError: column “userId” contains null values" Error
Checking DB would tell otherwise, strange bug.
sorry but where is this “destination folder for tsc” Thanks in advance
besides setting up the column as nullable, you can also setup a default value! 😃 Which makes a lot of sense:
Running in to this issue too, with a ManyToOne relationship resetting join column values to
nullon every restart.I want to keep the advantages of the
synchronizefunctionality, and would prefer not to have to track config exceptions in individual entities. Can confirm removing thedistfolder and restarting doesn’t resolve. Changing the order of entity creation (as suggested by @andresogando) also doesn’t resolve.Many to One:
OneToMany:
TypeORM logging reveals:
I interpret this as the column being dropped and reinitiated, but have no clue as to why. I’ve used MTO/OTM joins all over my codebase, but can’t understand this anomaly.
@pleerock Can you please take a look on this issue, I have seen 2 issue posts that mention the exact same problem from 2018! This issue is very annoying and I am losing time here. It seems that the issue occurs on the last column every time.
Edit: this issue occurs only when modifying the entity data by adding 1 or more columns after you run the project. Is there a way to clear the cache/(typeorm)files to have a clean start?