Hi everyone,
Given that I have a django project with the following database setup:
‘default’ = sqlite3, mainly used for the storage of user, group, contenttype, migration etc…
‘mssql’=sql server, mainly used for data storage
both databases need read, write, and migration permission. mssql db is created since I don’t have permissions for database creation in sql server. Otherwise, I’d set mssql as default database.
Initially, the django_migrations table has been created after running the following
python manage.py makemigrations
python manage.py migrate
Let’s say a model table has been created under an app ‘team_app’, when I run the following command to get the table migrated to mssql database, the following error came out
python manage.py migrate --database mssql
Running migrations:
Applying contenttypes.0001_initial...
pyodbc.ProgrammingError: ('42501', "[42501] [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]There is already an object named 'django_migrations' in the database. (2714) (SQLExecDirectW")
.
.
.
django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table (('42501', "[42501] [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]There is already an object named 'django_migrations' in the database. (2714) (SQLExecDirectW")
Here is my router.py partial code.
class CHRouter:
.
.
.
def allow_migration(self, db, app_label, model_name=None, **hints):
if app_label=="contenttypes" or model_name=="django_migrations":
return db=='default'
elif app_label=='team_app':
return db=='mssql'
.
.
.
Based on the information above, my I ask how to get this error fixed?
Thank you for your response in advance.
Kelvin