I'm using Django and SQL Server to create a simple django model as:
from django.db import models
class Person(models.Model):
first_name = models.CharField(max_length = 40)
last_name = models.CharField(max_length = 40)
class Meta:
managed = False
db_table = 'api].[persons'
My migration file is:
from django.db import migrations, models
class Migration(migrations.Migration):
initial = False
dependencies = [
]
operations = [
migrations.CreateModel(
name='Person',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False,
verbose_name='ID')),
('first_name', models.CharField(max_length=40)),
('last_name', models.CharField(max_length=40)),
],
options={
'db_table': 'api].[persons',
'managed': False,
},
),
]
Now when i try to run migration using migrate
command, I'm getting error as:
Traceback (most recent call last):
File "C:\Python3\lib\site-packages\django\db\backends\utils.py", line 83, in _execute
return self.cursor.execute(sql)
File "C:\Python3\lib\site-packages\sql_server\pyodbc\base.py", line 547, in execute
return self.cursor.execute(sql, params)
pyodbc.Error: ('21000', '[21000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Subquery
returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. (512) (SQLExecDirectW); [21000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]The statement has been terminated. (3621)')
This is what my Database settings look like:
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME': 'Myname',
'HOST': myhost,
'USER': 'user',
'PASSWORD': 'pass',
'OPTIONS': {
'driver': 'ODBC Driver 17 for SQL Server',
'unicode_results': True,
}
},
'test': {
'ENGINE': 'sql_server.pyodbc',
'NAME': 'name',
'HOST': 'host2',
'USER': 'test_user',
'PASSWORD': 'test_pass',
'OPTIONS': {
'driver': 'ODBC Driver 17 for SQL Server',
'unicode_results': True,
}
},
}
I've not used sub-query anywhere in my model but I'm not sure why I'm getting this error.
Note: Django==2.1.15 django-pyodbc-azure==2.1.0.0