I have a django application and have backend as Microsoft sql server. For that, i have installed "pip install django-mssql-backend".
I have extended User model and added one additional field of confirm_password and same i am migrating, but i am getting below error
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial...Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\django\retailAudit\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\django\retailAudit\lib\site-packages\django\core\management\__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\django\retailAudit\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\django\retailAudit\lib\site-packages\django\core\management\base.py", line 398, in execute
output = self.handle(*args, **options)
File "C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\django\retailAudit\lib\site-packages\django\core\management\base.py", line 89, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\django\retailAudit\lib\site-packages\django\core\management\commands\migrate.py", line 246, in handle
fake_initial=fake_initial,
File "C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\django\retailAudit\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\django\retailAudit\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\django\retailAudit\lib\site-packages\django\db\migrations\executor.py", line 227, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\django\retailAudit\lib\site-packages\django\db\migrations\migration.py", line 126, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\django\retailAudit\lib\site-packages\django\db\migrations\operations\models.py", line 531, in database_forwards
getattr(new_model._meta, self.option_name, set()),
File "C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\django\retailAudit\lib\site-packages\sql_server\pyodbc\schema.py", line 156, in alter_unique_together
self.execute(sql)
File "C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\django\retailAudit\lib\site-packages\sql_server\pyodbc\schema.py", line 861, in execute
sql = str(sql)
File "C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\django\retailAudit\lib\site-packages\django\db\backends\ddl_references.py", line 201, in __str__
return self.template % self.parts
KeyError: 'include'
After this, i can see below two tables created in database
- django_migrations
- django_content_type
My Model is below:
from django.db import models
from django.contrib.auth.models import User
class UserMaster(models.Model):
user = models.OneToOneField(User, on_delete = models.CASCADE)
# Additional fields
confirm_password = models.CharField(max_length=10)
def __str__(self):
return self.user.username
Below is Forms.py
from django import forms
from django.contrib.auth.models import User
from retail_forms.models import UserMaster
class UserForm(forms.ModelForm):
password = forms.CharField(widget = forms.PasswordInput())
first_name = forms.CharField(required=True)
last_name = forms.CharField(required=True)
class Meta():
model = User
fields = ('first_name','last_name','email','username','password')
class UserMasterForm(forms.ModelForm):
confirm_password = forms.CharField(required=True)
class Meta():
model = UserMaster
fields = ('confirm_password',)
Django version: 3.2
Can someone help.
Diagnosis :
This is an incompatibility issue between django-mssql-backend and django. django-mssql-backend supports Django 3.0+ only.
Solution :
Rollback to Django 3.0.14 and then run your migrations. It works fine.
Alternatively, you can try this fork supporting 3.2 : https://github.com/microsoft/mssql-django/issues/50