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.

Understanding dropSchema, synchronize and migrationRun

See original GitHub issue

Issue type:

[x] question [ ] bug report [ ] feature request [x] 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:

Hi,

I am a new user trying to understand some key concepts.

After reading the docs I am not sure that I understand the difference between dropSchema and synchronize? Does dropSchema connection option delete all tables for entities marked with the @Entity decorator every time a new connection is made while the application is running? The difference between this and synchronize is that with synchronize this only happens once, i.e. each time the application is started???

Does dropSchema and synchronize connection options conflict with option migrationsRun? Are they mutually exclusive, since if an entity schema (table) is created and a migration is run that creates that same table then a conflict has occurred???

Kind Regards

dcs3spp

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
elderapocommented, Sep 11, 2019

dropSchema drops all tables within the specified database (along with the records).

synchronize called without arguments tries to “auto synchronize” current DB schema to match typeorm entities. If called with true as first argument it drops DB and then recreates DB structure from typeorm entities.

I would say this “auto synchronization” is only viable for development. In production, you should just use migrations to update your DB.

7reactions
iyobocommented, Sep 17, 2019

I have synchronize set to true, but I don’t think it drops my DB in dev. I get errors like null value in column "oldColumn" violates not-null constraint when oldColumn has been deleted in the model.

I have even manually dropped that schema and relaunched my app, but it recreates the schema and I still get this same error. Like it is caching the old model structure and just using that structure cache instead of reading the current model as is upon launch in dev. Not sure whats going on. Pretty frustrating.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrations Over Synchronize in TypeORM | by Uthpala Pitawela
Synchronize makes the entity sync with the database every time you run your application. Hence, whenever you add columns ... npm run typeorm...
Read more >
Migrations - typeorm - GitBook
The migration:run and migration:revert commands only work on .js files. Thus the typescript files need to be compiled before running the commands. Alternatively ......
Read more >
Sequelize.js: how to use migrations and sync - Stack Overflow
Run sequelize db:migrate. Running migrations on production. Obviously you can't ssh to production server and run migrations by hands. Use umzug, ...
Read more >
Top 5 typeorm Code Examples - Snyk
Learn more about how to use typeorm, based on typeorm code examples created from the most popular ways it is used in public...
Read more >
MySQL Workbench Manual :: 9.5.1 Database Synchronization
Synchronize data between models, databases, and SQL files. ... Or a temporary workaround is to delete the DROP SCHEMA IF EXISTS line from...
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