在新的MSSQL服务器上运行迁移时,出现以下错误

2024-09-30 05:24:13 发布

您现在位置:Python中文网/ 问答频道 /正文

  Applying account.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 "/home/cagenix/.local/lib/python3.8/site-packages/django/core/management/                                                                                                             __init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/home/cagenix/.local/lib/python3.8/site-packages/django/core/management/                                                                                                             __init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/cagenix/.local/lib/python3.8/site-packages/django/core/management/                                                                                                             base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/cagenix/.local/lib/python3.8/site-packages/django/core/management/                                                                                                             base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/home/cagenix/.local/lib/python3.8/site-packages/django/core/management/                                                                                                             base.py", line 89, in wrapped
    res = handle_func(*args, **kwargs)
  File "/home/cagenix/.local/lib/python3.8/site-packages/django/core/management/                                                                                                             commands/migrate.py", line 244, in handle
    post_migrate_state = executor.migrate(
  File "/home/cagenix/.local/lib/python3.8/site-packages/django/db/migrations/ex                                                                                                             ecutor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_i                                                                                                             nitial=fake_initial)
  File "/home/cagenix/.local/lib/python3.8/site-packages/django/db/migrations/ex                                                                                                             ecutor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_                                                                                                             initial)
  File "/home/cagenix/.local/lib/python3.8/site-packages/django/db/migrations/ex                                                                                                             ecutor.py", line 230, in apply_migration
    migration_recorded = True
  File "/home/cagenix/.local/lib/python3.8/site-packages/django/db/backends/base                                                                                                             /schema.py", line 118, in __exit__
    self.execute(sql)
  File "/usr/local/lib/python3.8/dist-packages/sql_server/pyodbc/schema.py", lin                                                                                                             e 871, in execute
    sql = str(sql)
  File "/home/cagenix/.local/lib/python3.8/site-packages/django/db/backends/ddl_                                                                                                             references.py", line 201, in __str__
    return self.template % self.parts
KeyError: 'include'

这段代码在我的网站上处理在线用户的部分有问题,我不知道到底是什么导致了问题,但是如果我第二次尝试运行迁移,它会说已经存在一个名为account_的db用户。如果您需要任何其他信息,请询问

编辑1

from django.contrib import admin
from django.urls import include, path

from account.views import (
    registration,
    logout_view,
    login_view,
#    account_edit_view,
    account_view,
    account_create_barzero_order,
    print_barzero_order_view,
    choose_order_type,
)
from framework.views import(
    index
)

urlpatterns = [
    path('', index, name='home'),
    path('register/', registration, name="register"),
    path('logout/', logout_view, name="logout"),
    path('login/', login_view, name="login"),
#    path('account/edit/', account_edit_view, name="account_edit"),
    path('account/',account_view, name="account"),
    path('admin/', admin.site.urls),
    path('account/AddOrder/BarZero', account_create_barzero_order, name="create_barzero_order"),
    path('account/order/<int:order_id>', print_barzero_order_view, name="print_barzero_order"),
    path('account/order/choose', choose_order_type , name="choose_order_type")
]

编辑2

在从URL.py中删除include后,由于意识到它没有在任何地方使用,我重新运行迁移,并出现此错误

File "/home/cagenix/.local/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
  return self.cursor.execute(sql, params)
File "/usr/local/lib/python3.8/dist-packages/sql_server/pyodbc/base.py", line 555, in execute
  return self.cursor.execute(sql, params)
pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Column 'Prosthodontist.Customer Number' is not the same data type as referencing column 'account_user.prosthodontist_id' in foreign key 'account_user_prosthodontist_id_8fda3091_fk_Prosthodontist_Customer Number'. (1778) (SQLExecDirectW)")

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

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 "/home/cagenix/.local/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/home/cagenix/.local/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/cagenix/.local/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/cagenix/.local/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/home/cagenix/.local/lib/python3.8/site-packages/django/core/management/base.py", line 89, in wrapped
    res = handle_func(*args, **kwargs)
  File "/home/cagenix/.local/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 244, in handle
    post_migrate_state = executor.migrate(
  File "/home/cagenix/.local/lib/python3.8/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 "/home/cagenix/.local/lib/python3.8/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 "/home/cagenix/.local/lib/python3.8/site-packages/django/db/migrations/executor.py", line 230, in apply_migration
    migration_recorded = True
  File "/home/cagenix/.local/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 118, in __exit__
    self.execute(sql)
  File "/usr/local/lib/python3.8/dist-packages/sql_server/pyodbc/schema.py", line 882, in execute
    cursor.execute(sql, params)
  File "/home/cagenix/.local/lib/python3.8/site-packages/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/home/cagenix/.local/lib/python3.8/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/cagenix/.local/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/home/cagenix/.local/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/cagenix/.local/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.8/dist-packages/sql_server/pyodbc/base.py", line 555, in execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Column 'Prosthodontist.Customer Number' is not the same data type as referencing column 'account_user.prosthodontist_id' in foreign key 'account_user_prosthodontist_id_8fda3091_fk_Prosthodontist_Customer Number'. (1778) (SQLExecDirectW)")

Tags: djangoinpyselfhomeexecutedblib

热门问题