question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

columns are dropped and recreated at server start using oracle db

See original GitHub issue

Issue 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:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:8

github_iconTop GitHub Comments

2reactions
ataquinocommented, Jul 13, 2020

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 the up() method was creating the column with type varchar(max) and the down() method was creating it as varchar(MAX). So I changed length: 'max' to length: 'MAX' and the problem went away.

Maybe something similar is happening in these other cases?

2reactions
hsharghicommented, Jul 9, 2020

Same here using it with sqlite. I see some strange behavior in addition to dropping tables, like:

renaming column "department" in to "department"

Anyone found a way to fix it?

Update: Models with column type simple-enum will cause type-orm to drop and recreate the table

Read more comments on GitHub >

github_iconTop Results From Across the Web

Drop column command - Ask TOM
Drop column generates proportionately massive amounts of redo and in my experience is a horrible way to remove columns. The table is locked...
Read more >
Behavior Changes, Deprecated and Desupported Features for ...
Review for information about Oracle Database 19c changes, deprecations, and desupports, as well as deprecations and desupports in Oracle ...
Read more >
Alter table add column - Ask TOM
Alter table add column Hi,I want to add a column in table not at the last but in between the table without dropping...
Read more >
ALTER TABLE
Purpose. Use the ALTER TABLE statement to alter the definition of a nonpartitioned table, a partitioned table, a table partition, or a table...
Read more >
SQL error messages and exceptions - Oracle Help Center
Exceptions that begin with an X are specific to Derby. ... 01009, Generated column <columnName> dropped from table <tableName> .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found