gpt4 book ai didi

mysql - 迁移失败,出现警告 "' utf 8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release'

转载 作者:行者123 更新时间:2023-11-29 15:45:34 29 4
gpt4 key购买 nike

在我的 Django 项目中,我试图将数据库字段从 OneToOne 更改为foreignKey。当我运行“python manage.py migrate”时,它会因一个长回溯而中断,并以我在标题中引用的警告结尾。我知道其他人也遇到过这个问题,但我找不到解决方案。

我已将以下内容添加到我的 local_settings.py 数据库中:

'OPTIONS': {
'autocommit': True,
'charset': 'utf8mb4',
}

起初我尝试简单地将 OneToOne 更改为foreignkey,但遇到了这个问题。因此,我决定分步骤执行此操作,首先删除该字段,然后使用新的字段类型添加它。但我什至无法删除该字段。

这是由 makemigrations 生成的迁移文件,也是 migrate 中断的文件:

# Generated by Django 2.2.3 on 2019-07-18 09:59

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('sweaters', '0011_auto_20190718_0954'),
]

operations = [
migrations.RemoveField(
model_name='sweater',
name='yarn_for',
),
]

这是我得到的完整回溯:

$ python manage.py migrate
Operations to perform:
Apply all migrations: account, admin, auth, contenttypes, sessions, sweaters
Running migrations:
Applying sweaters.0012_remove_sweater_yarn_for...Traceback (most recent call last):
File "/Users/frankjernigan/Documents/webdev/phrancko-web-dev/phrancko.com/phrancko-project/myenv/lib/python3.7/site-packages/django/db/utils.py", line 96, in inner
return func(*args, **kwargs)
File "/Users/frankjernigan/Documents/webdev/phrancko-web-dev/phrancko.com/phrancko-project/myenv/lib/python3.7/site-packages/mysql/connector/cursor.py", line 897, in fetchall
self._handle_eof(eof)
File "/Users/frankjernigan/Documents/webdev/phrancko-web-dev/phrancko.com/phrancko-project/myenv/lib/python3.7/site-packages/mysql/connector/cursor.py", line 838, in _handle_eof
self._warnings[0][1], self._warnings[0][2])
mysql.connector.errors.DatabaseError: 3719: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.

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

Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/Users/frankjernigan/Documents/webdev/phrancko-web-dev/phrancko.com/phrancko-project/myenv/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/Users/frankjernigan/Documents/webdev/phrancko-web-dev/phrancko.com/phrancko-project/myenv/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/frankjernigan/Documents/webdev/phrancko-web-dev/phrancko.com/phrancko-project/myenv/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/frankjernigan/Documents/webdev/phrancko-web-dev/phrancko.com/phrancko-project/myenv/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/Users/frankjernigan/Documents/webdev/phrancko-web-dev/phrancko.com/phrancko-project/myenv/lib/python3.7/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/Users/frankjernigan/Documents/webdev/phrancko-web-dev/phrancko.com/phrancko-project/myenv/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 234, in handle
fake_initial=fake_initial,
File "/Users/frankjernigan/Documents/webdev/phrancko-web-dev/phrancko.com/phrancko-project/myenv/lib/python3.7/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 "/Users/frankjernigan/Documents/webdev/phrancko-web-dev/phrancko.com/phrancko-project/myenv/lib/python3.7/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 "/Users/frankjernigan/Documents/webdev/phrancko-web-dev/phrancko.com/phrancko-project/myenv/lib/python3.7/site-packages/django/db/migrations/executor.py", line 245, in apply_migration
state = migration.apply(state, schema_editor)
File "/Users/frankjernigan/Documents/webdev/phrancko-web-dev/phrancko.com/phrancko-project/myenv/lib/python3.7/site-packages/django/db/migrations/migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/Users/frankjernigan/Documents/webdev/phrancko-web-dev/phrancko.com/phrancko-project/myenv/lib/python3.7/site-packages/django/db/migrations/operations/fields.py", line 178, in database_forwards
schema_editor.remove_field(from_model, from_model._meta.get_field(self.name))
File "/Users/frankjernigan/Documents/webdev/phrancko-web-dev/phrancko.com/phrancko-project/myenv/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 479, in remove_field
fk_names = self._constraint_names(model, [field.column], foreign_key=True)
File "/Users/frankjernigan/Documents/webdev/phrancko-web-dev/phrancko.com/phrancko-project/myenv/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 1115, in _constraint_names
constraints = self.connection.introspection.get_constraints(cursor, model._meta.db_table)
File "/Users/frankjernigan/Documents/webdev/phrancko-web-dev/phrancko.com/phrancko-project/myenv/lib/python3.7/site-packages/mysql/connector/django/introspection.py", line 320, in get_constraints
for constraint, column, ref_table, ref_column in cursor.fetchall():
File "/Users/frankjernigan/Documents/webdev/phrancko-web-dev/phrancko.com/phrancko-project/myenv/lib/python3.7/site-packages/django/db/utils.py", line 96, in inner
return func(*args, **kwargs)
File "/Users/frankjernigan/Documents/webdev/phrancko-web-dev/phrancko.com/phrancko-project/myenv/lib/python3.7/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/Users/frankjernigan/Documents/webdev/phrancko-web-dev/phrancko.com/phrancko-project/myenv/lib/python3.7/site-packages/django/db/utils.py", line 96, in inner
return func(*args, **kwargs)
File "/Users/frankjernigan/Documents/webdev/phrancko-web-dev/phrancko.com/phrancko-project/myenv/lib/python3.7/site-packages/mysql/connector/cursor.py", line 897, in fetchall
self._handle_eof(eof)
File "/Users/frankjernigan/Documents/webdev/phrancko-web-dev/phrancko.com/phrancko-project/myenv/lib/python3.7/site-packages/mysql/connector/cursor.py", line 838, in _handle_eof
self._warnings[0][1], self._warnings[0][2])
django.db.utils.DatabaseError: (3719, "3719: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.", None)

最佳答案

这是 MySQL 切换默认设置的问题,并且 mysql-connector-python 不是最新的。这里提供了解决方法:

https://code.djangoproject.com/ticket/29678

您使用的 mysql-connector-python 版本是什么?我想知道是否可以通过链接中的解决方法在更新的版本中对其进行修补。

关于mysql - 迁移失败,出现警告 "' utf 8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57092680/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com