Skip to content

Commit 3b4d5e3

Browse files
committed
fix(migrate): master-slave database error
1 parent 7233f51 commit 3b4d5e3

3 files changed

Lines changed: 6 additions & 2 deletions

File tree

rootfs/api/migrations/0017_migration_deployed_ptypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
def migration_deployed_ptypes(apps, schema_editor):
8-
for release in Release.objects.all().using("default"):
8+
for release in Release.objects.all():
99
deployed_ptypes = set()
1010
for condition in release.conditions:
1111
if condition["ptypes"] is None:

rootfs/api/migrations/0019_migration_config_values_and_typed_values.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def migration_values(apps, schema_editor):
99
cursor.execute("SELECT uuid,values,typed_values,registry FROM api_config")
1010
for uuid, values, typed_values, registry in cursor:
1111
new_values = []
12-
config = Config.objects.using('default').get(pk=uuid)
12+
config = Config.objects.get(pk=uuid)
1313
for name, value in json.loads(values).items():
1414
new_values.append({
1515
"name": name,

rootfs/api/routers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@ def allow_relation(self, obj1, obj2, **hints):
3232
return True
3333

3434
def allow_migrate(self, db, app_label, model_name=None, **hints):
35+
if 'replica' in settings.DATABASES and 'model' in hints:
36+
model = hints['model']
37+
tracker_key = ".".join([model.__module__, model.__name__])
38+
setattr(self._tracker, tracker_key, 'default')
3539
return True

0 commit comments

Comments
 (0)