- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经尝试这个问题很长时间了。但我似乎找不到解决方案。我正在尝试将我的项目部署在 pythonanywhere 上,我选择了 MySQL。每当我尝试使用 python manage.py migrate 迁移我的模型时。我收到以下错误:
这是我的模型。
models.py
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class Thing(models.Model):
thing_name = models.CharField(max_length=64, unique=True)
def __str__(self):
return self.hobby_name
class Person(models.Model):
user = models.OneToOneField(
User,
on_delete=models.CASCADE,
)
first_name = models.CharField(max_length=64, null=True, blank=False)
last_name = models.CharField(max_length=64, null=True, blank=False)
hobbies = models.ManyToManyField(Hobby, blank=False)
email = models.EmailField(max_length=64, blank=True, null=True, unique=True)
city = models.CharField(max_length=64, null=True, blank=False)
zip_code = models.CharField(max_length=10, null=True, blank=False)
description = models.TextField(max_length=2048, null=True, blank=True)
gender = models.CharField(max_length=1,
choices=(
('N', 'No answer'),
('M', 'Male'),
('F', 'Female'),
('O', 'Other')
), null=True, blank=True, default="N"
)
bad = models.BooleanField(default=False)
good = models.BooleanField(default=True)
maximum_hours = models.PositiveIntegerField(default=2)
def __str__(self):
try:
string = self.first_name + " " + self.last_name
except:
string = "name_error"
return string
最后一点是,我已经多次删除并重新创建了数据库。每次通过:
CREATE DATABASE database_name DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
我正在将所有这些部署到 Pythonanywhere。
模型 Thing 实际上变成了一张 table 。但模型 Person 却没有。
编辑:这是完整的回溯
(hobbyin) 01:16 ~/hobbyin (master)$ python manage.py migrate
System check identified some issues:
WARNINGS:
?: (mysql.W002) MySQL Strict Mode is not set for database connection 'default'
HINT: MySQL's Strict Mode fixes many data integrity problems in MySQL, such as data truncation upon insertion, by escalating warnings into errors. It
is strongly recommended you activate it. See: https://docs.djangoproject.com/en/2.0/ref/databases/#mysql-sql-mode
Operations to perform:
Apply all migrations: account, admin, auth, contenttypes, external_page, sessions, sites, socialaccount
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying account.0001_initial... OK
Applying account.0002_email_max_length... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying auth.0009_alter_user_last_name_max_length... OK
Applying external_page.0001_initial...Traceback (most recent call last):
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/django/db/backends/utils.py", line 83, in _execute
return self.cursor.execute(sql)
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 71, in execute
return self.cursor.execute(query, args)
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/MySQLdb/cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/MySQLdb/connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/MySQLdb/cursors.py", line 247, in execute
res = self._query(query)
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/MySQLdb/cursors.py", line 412, in _query
rowcount = self._do_query(q)
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/MySQLdb/cursors.py", line 375, in _do_query
db.query(q)
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/MySQLdb/connections.py", line 276, in query
_mysql.connection.query(self, query)
_mysql_exceptions.OperationalError: (1071, 'Specified key was too long; max key length is 767 bytes')
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 "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/django/core/management/base.py", line 335, in execute
output = self.handle(*args, **options)
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 200, in handle
fake_initial=fake_initial,
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/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/maxxie/.virtualenvs/hobbyin/lib/python3.6/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/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/django/db/migrations/migration.py", line 122, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/django/db/migrations/operations/models.py", line 92, in database_forwards
schema_editor.create_model(model)
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 314, in create_model
self.execute(sql, params or None)
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 133, in execute
cursor.execute(sql, params)
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/django/db/backends/utils.py", line 83, in _execute
return self.cursor.execute(sql)
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 71, in execute
return self.cursor.execute(query, args)
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/MySQLdb/cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/MySQLdb/connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/MySQLdb/cursors.py", line 247, in execute
res = self._query(query)
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/MySQLdb/cursors.py", line 412, in _query
rowcount = self._do_query(q)
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/MySQLdb/cursors.py", line 375, in _do_query
db.query(q)
File "/home/maxxie/.virtualenvs/hobbyin/lib/python3.6/site-packages/MySQLdb/connections.py", line 276, in query
_mysql.connection.query(self, query)
django.db.utils.OperationalError: (1071, 'Specified key was too long; max key length is 767 bytes')
最佳答案
找到答案了。当您将代码部署到生产环境时。确保您的迁移文件已删除。否则可能会导致像这样的意外错误。
关于python - 在 MySQL 上部署 Django 给出 #1071 错误 "Specified key was too long",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51334487/
在 CSS 中,我从来没有真正理解为什么会发生这种情况,但每当我为某物分配 margin-top:50% 时,该元素就会被推到页面底部,几乎完全消失这一页。我假设 50% 时,该元素将位于页面的中间位
我想在 MongoDB 中使用 Grails2.5 中的“ElasticSearch”插件。我的“BuildConfig.groovy”文件是: grails.servlet.version = "3
我有一个我想要处理的 OHLC 股票报价数组。 Open High Low Close Volume 2003-01-05
我尝试创建一个PreparedStatement: stmt = conn.prepareStatement("SELECT POLBRP, POLTYP, POLNOP, INCPTP, TRMTH
我的目录结构如下: root libA CMakeLists.txt ClassA.cpp libB CMakeLists.txt ClassB.cpp s
我是 DBMS 的新手。我在每个用户的不同 csv 文件中都有车辆痕迹。格式:名称,时间戳,纬度,经度,randomId。例如:user0,2008-10-2309:42:25,441972.6942
我需要为我的应用程序打上烙印,并且只需要自定义少量图像,代码库是相同的,只是生成的常量很少。 由于aapt 允许指定许多资源目录,有没有办法在Eclipse .classpath 文件中指定res 目
我希望在我的应用程序中实现 JWT,因为我正在通过引用以下内容对其进行一些研发:https://stormpath.com/blog/jwt-java-create-verify .当我尝试通过提取声
我正在尝试通过设置限制获取数据并根据时间戳对数据进行排序,但在运行应用程序时崩溃并显示此错误消息: 查询无效。在指定顺序之前不得指定起点。 我不知道为什么会这样。如何解决? 我需要数据序列和排序。
我正在使用Elasticsearch和Tire进行Rails3项目。当我尝试运行Elastic-search时,安装它后,出现以下错误: The stack size specified is too
我创建了一个简单的函数来执行 Http PUT 请求 - public string checkIfUserExists(string userName) { var endP
Java 安全管理器允许通过定义如下子句来指定某些代码段的权限: ... grant codebase http://foo.bar.com/test.jar { permission java
这更像是一种验证。 在 Oracle/Java 教程页面上,例如 this , 我一直看到catch 旁边的“specify”就好像它是另一个语句在异常处理中具有一些功能。 据我所知,“catch o
本文整理了Java中org.batfish.specifier.ZoneNameRegexInterfaceSpecifier类的一些代码示例,展示了ZoneNameRegexInterfaceSpe
我正在尝试运行以下命令: ionic cordova run android --device 但我收到以下错误 BUILD FAILED in 3s (node:3956) Unha
在不包含 viewport 元标记的网页上,大多数移动浏览器会将页面上的部分或全部字体“提升”到大于 css 指定的大小。例如,在移动版 Safari 上,7px 的指定大小将提升为类似 12px 的
嗨,我不了解 keras fit_generator 文档。 我希望我的困惑是理性的。 有一个batch_size还有分批训练的概念。使用 model_fit() ,我指定一个 batch_size
我使用 IProviderSearchContext 在 Sitecore 8.1(Lucene 搜索)中搜索特定项目,并获得每个项目的两个版本(en、ar)。我的问题是:我是否必须为每个查询指定:
Except in a declaration of a constructor, destructor, or conversion function, at least one defining-
使用 GooglePageSpeed 分析在线商店(Shopware)导致每个图像上出现许多“未指定到期时间”的线条。 我想知道是因为网络服务器 (nginx) 在所有图像的响应中添加了 Last-M
我是一名优秀的程序员,十分优秀!