synchronize=true in connection does not update database schema in DB
See original GitHub issueIssue Description
Setting synchronize: true
in createConnection
does not update schema in DB (postgres 9.6) if there has been any change in entity schema after table is created. This issue occured in 0.2.34, 0.2.35. Issue does not exist in 0.2.33.
Expected Behavior
With synchronize: true
, any change in entity should be updated in related database table.
Actual Behavior
With synchronize: true
, table is created if it does not exist, but any further change in entity schema do not lead to change in database table.
Steps to Reproduce
- Set
synchronize=true
in createConnection option - Update entity schema (e.g. adding a index) for a entity for which table already exits in database
- The entity schema update is not reflected in database table (e.g Newly added index is not created in database).
// Options used for creating connection
const conn = await createConnection({
type: 'postgres',
host: process.env.DB_HOST as string,
port: parseInt(process.env.DB_PORT as string, 10),
username: process.env.DB_USERNAME as string,
password: process.env.DB_PASSWORD as string,
database: process.env.DB_NAME as string,
schema: 'public',
logging: true,
entities,
namingStrategy: new SnakeNamingStrategy(),
synchronize: true,
});
My Environment
Dependency | Version |
---|---|
Operating System | MacOS Intel Big Sur 11.5 |
Node.js version | 14.17.3 |
Typescript version | 4.3.5 |
TypeORM version | 0.2.35 |
Additional Context
Issue does not exist in version 0.2.33. Noticed in 0.2.34 and 0.2.35.
Relevant Database Driver(s)
DB Type | Reproducible |
---|---|
aurora-data-api |
no |
aurora-data-api-pg |
no |
better-sqlite3 |
no |
cockroachdb |
no |
cordova |
no |
expo |
no |
mongodb |
no |
mysql |
no |
nativescript |
no |
oracle |
no |
postgres |
yes |
react-native |
no |
sap |
no |
sqlite |
no |
sqlite-abstract |
no |
sqljs |
no |
sqlserver |
no |
Are you willing to resolve this issue by submitting a Pull Request?
- ✖️ Yes, I have the time, and I know how to start.
- ✅ Yes, I have the time, but I don’t know how to start. I would need guidance.
- ✖️ No, I don’t have the time, but I can support (using donations) development.
- ✖️ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (7 by maintainers)
Top Results From Across the Web
The database schema is not in sync with the current mapping ...
Run this command to show the differences in the SQL without having to dump your db: php bin/console doctrine:schema:update --dump-sql.
Read more >Migrations Over Synchronize in TypeORM | by Uthpala Pitawela
First of all, you need to check whether the “synchronize” attribute of ormconfig.json is set to true. This is the entity and database...
Read more >FAQ - typeorm - GitBook
How do I update a database schema? · Use synchronize: true in data source options: import { DataSource } from "typeorm". . const...
Read more >DbSchema Schema Synchronization
Synchronize the Model with any Database · Select the Refresh button from the upper tool menu; · If your schema is not synchronized,...
Read more >Schema is not updating – IDEs Support (IntelliJ Platform)
Four selections above the 'Synchronize' on your screenshot, there is Database Tools -> Manage Shown Schemas... then check if the schemata you ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yep this isn’t working. Would be nice to get this fixed 😃
Confirmed. Temporary solution is to remove
schema: 'public',
- by default it is alreadypublic
and you can omit it.