Error: There is already an object named 'django_migrations' in the database.

what I meant was adding this new database source to django project.

yes. because you are adding new db, there is no data in msql db.

‘mssql’ is a legacy database with loads of data in it :slight_smile: that’s the reason why I said deleting the DB is not an option

If you use a connection to a DB where data is added in a different way, use the managed option.

So do you mean I need to add managed=True in model table because of the legacy database that I used? But the default value of managed option is already True.

I am not trying to read a legacy table from ‘mssql’, but instead try to migrate a newly create model table to it.

What do you mean, editing a model that declares to only use reads?

What do you mean, editing a model that declares to only use reads?

I’m still a little confused here.

If the database already exists, and has data in it, why are you trying to run migrations on it? Migrations are only used when you’re looking to alter the schema.
They’re not needed with existing data.

Also, if you’re getting an error with the migration, please post the complete error with the traceback. It is possible that there’s a different root cause than the obvious error being displayed.

Hi @KenWhitesell ,

‘mssql’ is a legacy database which already contains lots of tables that have been created out of django scope. The reason why I still need to have migrate to this ‘mssql’ db is that when I created a new model table in django, I’d migrate and store this newly created model in ‘mssql’ db and treat ‘mssql’ db as data storage database. The ‘default’ sqlite db will only store admin, contenttype, auth, etc. information and be treated as admin database only.

By the way, I kind of found the root cause. While running python manage.py migrate --database mssql, the table django_migrations created in mssql db is named as [database_name].[my_username].[django_migrations]. But I guess django is expected to have dbo as schema instead [database_name].[dbo].[django_migrations]. But it’s my blind guess, not 100% sure that’s the root cause.

Given my guess was correct, would it be possible that we could define django to use dbo schema instead of my user name?

Thank you for your response.

Kelvin