python manage.py magrate gives the below error with SQL SERVER (Please help)

348 views
Skip to first unread message

Vikram Gajjala

unread,
Aug 10, 2021, 9:51:01 AM8/10/21
to Django users
SQL Server 2019
Python 3.9.6
pip 21.2.3
python -m django --version 3.2.6

asgiref              3.4.1
astroid              2.6.6
colorama             0.4.4
Django               3.2.6
django-mssql-backend 2.8.1
django-pyodbc        1.1.3
django-tastypie      0.14.3
isort                5.9.3
lazy-object-proxy    1.6.0
mccabe               0.6.1
pip                  21.2.3
pylint               2.9.6
pyodbc               4.0.31
python-dateutil      2.8.2
python-mimeparse     1.6.0
pytz                 2021.1
setuptools           56.0.0
six                  1.16.0
sqlparse             0.4.1
toml                 0.10.2
wrapt                1.12.1


(mysite) C:\Python_Vik\mysite\myfirstsite>python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, polls, sessions
Running migrations:
  Applying polls.0004_choice_question...Traceback (most recent call last):
  File "C:\Python_Vik\mysite\lib\site-packages\django\db\backends\utils.py", line 82, in _execute
    return self.cursor.execute(sql)
  File "C:\Python_Vik\mysite\lib\site-packages\sql_server\pyodbc\base.py", line 553, in execute
    return self.cursor.execute(sql, params)
pyodbc.ProgrammingError: ('42S01', "[42S01] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]There is already an object named 'polls_question' in the database. (2714) (SQLExecDirectW)")

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Python_Vik\mysite\myfirstsite\manage.py", line 22, in <module>
    main()
  File "C:\Python_Vik\mysite\myfirstsite\manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Python_Vik\mysite\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "C:\Python_Vik\mysite\lib\site-packages\django\core\management\__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python_Vik\mysite\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Python_Vik\mysite\lib\site-packages\django\core\management\base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "C:\Python_Vik\mysite\lib\site-packages\django\core\management\base.py", line 89, in wrapped
    res = handle_func(*args, **kwargs)
  File "C:\Python_Vik\mysite\lib\site-packages\django\core\management\commands\migrate.py", line 244, in handle
    post_migrate_state = executor.migrate(
  File "C:\Python_Vik\mysite\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:\Python_Vik\mysite\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:\Python_Vik\mysite\lib\site-packages\django\db\migrations\executor.py", line 227, in apply_migration
    state = migration.apply(state, schema_editor)
  File "C:\Python_Vik\mysite\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:\Python_Vik\mysite\lib\site-packages\django\db\migrations\operations\models.py", line 92, in database_forwards
    schema_editor.create_model(model)
  File "C:\Python_Vik\mysite\lib\site-packages\sql_server\pyodbc\schema.py", line 809, in create_model
    self.execute(sql, params or None)
  File "C:\Python_Vik\mysite\lib\site-packages\sql_server\pyodbc\schema.py", line 872, in execute
    cursor.execute(sql, params)
  File "C:\Python_Vik\mysite\lib\site-packages\django\db\backends\utils.py", line 98, in execute
    return super().execute(sql, params)
  File "C:\Python_Vik\mysite\lib\site-packages\django\db\backends\utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "C:\Python_Vik\mysite\lib\site-packages\django\db\backends\utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "C:\Python_Vik\mysite\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Python_Vik\mysite\lib\site-packages\django\db\utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "C:\Python_Vik\mysite\lib\site-packages\django\db\backends\utils.py", line 82, in _execute
    return self.cursor.execute(sql)
  File "C:\Python_Vik\mysite\lib\site-packages\sql_server\pyodbc\base.py", line 553, in execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: ('42S01', "[42S01] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]There is already an object named 'polls_question' in the database. (2714) (SQLExecDirectW)")

Amitesh Sahay

unread,
Aug 10, 2021, 11:07:41 AM8/10/21
to Django users
check your database table though some UI. make sure that the " polls_question" is not there 


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/87f74b3a-71d2-4107-a3ed-77b9fb511b74n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages