Python3.9 django4.1 migrate出现错误(sqlite3)

@[toc](Python3.9 django4.1 migrate出现错误(sqlite3))

1、错误

# 使用django自带的数据库sqlite3
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}

python manage.py makemigrations 执行该命令没有报错
python manage.py migrate # 这里报错了

(py39env) D:\PersonalProject\MMS>python manage.py makemigrations
No changes detected

(py39env) D:\PersonalProject\MMS>python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions, users
Running migrations:
  Applying auth.0001_initial...Traceback (most recent call last):
  File "D:\PersonalProject\MMS\manage.py", line 22, in <module>
    main()
  File "D:\PersonalProject\MMS\manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "D:\py39env\lib\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "D:\py39env\lib\site-packages\django\core\management\__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "D:\py39env\lib\site-packages\django\core\management\base.py", line 402, in run_from_argv
    self.execute(*args, **cmd_options)
  File "D:\py39env\lib\site-packages\django\core\management\base.py", line 448, in execute
    output = self.handle(*args, **options)
  File "D:\py39env\lib\site-packages\django\core\management\base.py", line 96, in wrapped
    res = handle_func(*args, **kwargs)
  File "D:\py39env\lib\site-packages\django\core\management\commands\migrate.py", line 349, in handle
    post_migrate_state = executor.migrate(
  File "D:\py39env\lib\site-packages\django\db\migrations\executor.py", line 135, in migrate
    state = self._migrate_all_forwards(
  File "D:\py39env\lib\site-packages\django\db\migrations\executor.py", line 167, in _migrate_all_forwards
    state = self.apply_migration(
  File "D:\py39env\lib\site-packages\django\db\migrations\executor.py", line 255, in apply_migration
    migration_recorded = True
  File "D:\py39env\lib\site-packages\django\db\backends\sqlite3\schema.py", line 39, in __exit__
    self.connection.check_constraints()
  File "D:\py39env\lib\site-packages\django\db\backends\sqlite3\base.py", line 289, in check_constraints
    for column_name, (
ValueError: too many values to unpack (expected 2)
# ValueError:解包的值太多(预期2),一直报这个错误

2、我改用postgresql数据库问题解决了

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'TEST',
        'USER': 'postgres',
        'PASSWORD': 'postgres',
        'HOST': '127.0.0.1',
        'PORT': '5432'
    }
}

使用PostgreSQL数据库问题解决了

难道是django4.1不兼容sqlite3???脑壳痛

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值