columns are dropped and recreated at server start using oracle db
See original GitHub issueIssue type:
[ ] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[x] oracle
[ ] postgres
[ ] cockroachdb
[x] 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:
We use sqlite for our local development and an oracle db for our deployed versions. When we start the server the first time using our oracle db everything works fine. All the tables are created. But when we start it a second time, typeorm says the columns changed, even though they didn’t, and drops all the constraints/columns and re-creates them right afterwards.
columns changed in "users". updating: id, createdBy, updatedBy, name
query: ALTER TABLE "users" DROP CONSTRAINT "PK_a3ffb1c0c8416b9fc6f907b7433"
query: ALTER TABLE "users" DROP COLUMN "id"
query: ALTER TABLE "users" ADD "id" varchar2(255) NOT NULL
query: ALTER TABLE "users" ADD CONSTRAINT "PK_a3ffb1c0c8416b9fc6f907b7433" PRIMARY KEY ("id")
This obviously leads to data loss and since it’s deleting/recreating column by column it messes up the oracle db and leads to following error as soon as data is inserted: QueryFailedError: ORA-01758: table must be empty to add mandatory (NOT NULL) column
if we use exactly the same configuration in an sqlite setup nothing like this happens and the db starts up without dropping any columns.
I set up a small project to recreate the issue: https://github.com/Gnilherk/typeormapp
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:8
I had a similar issue with
mssql
, columns with{ type: 'varchar', length: 'max' }
were always dropped and created, even when generating migrations. By looking at the migration file, I saw theup()
method was creating the column with typevarchar(max)
and thedown()
method was creating it asvarchar(MAX)
. So I changedlength: 'max'
tolength: 'MAX'
and the problem went away.Maybe something similar is happening in these other cases?
Same here using it with sqlite. I see some strange behavior in addition to dropping tables, like:
Anyone found a way to fix it?
Update: Models with column type
simple-enum
will cause type-orm to drop and recreate the table