Update model synchronization in sequelize.js to prevent automatic foreign key creation by adding constraints: false, ensuring foreign keys are managed through migrations only.
This commit is contained in:
@@ -105,7 +105,8 @@ const syncModelsWithUpdates = async (models) => {
|
||||
if (needsUpdate) {
|
||||
console.log('🔄 Schema-Updates nötig - verwende alter: true');
|
||||
for (const model of Object.values(models)) {
|
||||
await model.sync({ alter: true, force: false });
|
||||
// constraints: false verhindert, dass Sequelize Foreign Keys automatisch erstellt
|
||||
await model.sync({ alter: true, force: false, constraints: false });
|
||||
}
|
||||
console.log('✅ Schema-Updates abgeschlossen');
|
||||
} else {
|
||||
@@ -373,7 +374,8 @@ const getExpectedDefaultValue = (defaultValue) => {
|
||||
const updateSchema = async (models) => {
|
||||
console.log('🔄 Aktualisiere Datenbankschema...');
|
||||
for (const model of Object.values(models)) {
|
||||
await model.sync({ alter: true, force: false });
|
||||
// constraints: false verhindert, dass Sequelize Foreign Keys automatisch erstellt
|
||||
await model.sync({ alter: true, force: false, constraints: false });
|
||||
}
|
||||
console.log('✅ Datenbankschema aktualisiert');
|
||||
};
|
||||
@@ -474,7 +476,9 @@ const syncModelsAlways = async (models) => {
|
||||
}
|
||||
|
||||
try {
|
||||
await model.sync({ alter: true, force: false });
|
||||
// constraints: false verhindert, dass Sequelize Foreign Keys automatisch erstellt
|
||||
// Foreign Keys sollten nur über Migrations verwaltet werden
|
||||
await model.sync({ alter: true, force: false, constraints: false });
|
||||
} finally {
|
||||
// Restore VIRTUAL fields after sync
|
||||
for (const [key, attr] of Object.entries(virtualFields)) {
|
||||
|
||||
Reference in New Issue
Block a user