我的应用当前正在使用两个不同的数据库运行:默认为只读,而histo是我正在编写的数据库。
我已更改admin.py文件以更改默认数据库:
class MultiDBModelAdmin(admin.ModelAdmin):
using='histo'
def save_model(self, request, obj, form, change):
# Tell Django to save objects to the 'histo' database.
obj.save(using=self.using)
def delete_model(self, request, obj):
# Tell Django to delete objects from the 'histo' database
obj.delete(using=self.using)
def get_queryset(self, request):
# Tell Django to look for objects on the 'histo' database.
return super().get_queryset(request).using(self.using)
def formfield_for_foreignkey(self, db_field, request, **kwargs):
# Tell Django to populate ForeignKey widgets using a query
# on the 'histo' database.
return super().formfield_for_foreignkey(db_field, request, using=self.using, **kwargs)
def formfield_for_manytomany(self, db_field, request, **kwargs):
# Tell Django to populate ManyToMany widgets using a query
# on the 'histo' database.
return super().formfield_for_manytomany(db_field, request, using=self.using, **kwargs)
当我运行manage.py createsuperuser时,出现错误:
django.db.utils.ProgrammingError: relation "auth_user" does not exist
我尝试了manage.py migration --database = histo auth,但是仍然出现此错误。 我认为这与默认数据库处于只读状态有关。
您能帮我吗? 谢谢