Understanding dropSchema, synchronize and migrationRun
See original GitHub issueIssue 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:
- Created 4 years ago
- Reactions:1
- Comments:9 (1 by maintainers)
Top GitHub Comments
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 withtrue
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.
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.