-
-
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
synchronize drops (and then re-adds) json column in mariadb #3636
Comments
Same issue here. I investigated a bit and found that TypeORM thinks that the column name was changed, even though in the log they look exactly the same. |
I do not see this behaviour on mysql driver so it is mariadb specific. Maybe some difference in information schema. |
Could it be a difference between mysql and mysql2? I'll try the next time I'm at my laptop. Still seems like a bug more than a behavior specificality... |
I tried both mysql and mysql2 drivers with both MariaDB and MySQL, there's no difference. Here's one entity that suffers: import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm'
@Entity('users')
export class User {
@PrimaryGeneratedColumn()
id: string
@Column({ unique: true })
email: string
@Column({ nullable: true })
password: string
@Column('simple-json', { name: 'profile' })
profile: {
firstName: string
lastName: string
}
@Column({ default: true })
active: boolean
} Every time I restart the app with synchronization enabled, here's the log that I get:
Interesting thing is that it's not only the JSON columns that are being re-added every time. I have a primary generated uuid column in one table that gets re-added and for some reason a regular string column in another table. |
This bug is still there. I'm using MariaDB 10.3.14 and typeorm 0.2.16 |
The reason is that mariadb uses longtext instead. Type "simple-json" works fine. The solution can be by inserting |
I think migration from old text type to new json type shouldn't involve column dropping. |
this is bug in typeorm 0.2.19 too. |
same here, i encounter the same road-block. The columns are altered on each start. I'm running MariaDb 10.2.27 |
Same problem here with typeorm 0.2.22. Any idea when the issue will be fixed? |
* #3636 synchronize drops json column on mariadb * fixes failing test - QueryFailedError: ER_BLOB_CANT_HAVE_DEFAULT: BLOB/TEXT column 'data' can't have a default value * simple commit to trigger ci jobs
Unfortunately, for me this issue exists in It's only happening when my entity has a big column length: With My DB Config:
My Entity: import {
Column,
Entity,
PrimaryColumn,
} from "typeorm";
@Entity()
export class Config {
@PrimaryColumn()
public key: string;
@Column({length: 1000000000})
public value: string;
} The log:
As you can see, it's renaming |
@hrueger Seems your problem is not same as this one (about |
Any update on that ? my json columns drops everytime i sync db. |
Use simple-json column data type to avoid that |
Doing that you loose CHECK (JSON_VALID) constraint |
I used to have this problem until I realized that while I was using and connecting to a mariadb, I had |
Thanks @catt-stefano, your solution works. |
@catt-stefano This helped me. Finally no more DROP/ALTER table crap! You deserve a cookie. |
@catt-stefano Thank you, this also solved the behavior on my side :) |
Issue type:
[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ]
cordova
[ ]
mongodb
[ ]
mssql
[x]
mysql
/mariadb
[ ]
oracle
[ ]
postgres
[ ]
sqlite
[ ]
sqljs
[ ]
react-native
[ ]
expo
TypeORM version:
[ ]
latest
[ ]
@next
[0.2.13]
0.x.x
(or put your version here)Steps to reproduce or a small repository showing the problem:
I created and entity with a json column. Here is part of the entity:
I'll note that after creation, the "lexicon" column in the database is typed longtext.
Whenever synchronize is run, I see:
Which, of course deletes any data I had in that column.
I'm using MariaDB 10.2.10. In fact I upgraded to this version today specifically because it has support for json columns.
Before today I was just using a varchar column rather than a json column and storing strings - but of course that means converting objects to strings and back.
The text was updated successfully, but these errors were encountered: