我正在尝试在heroku
上部署我的应用,一切顺利,所有文件都已上传,但是一旦我运行heroku run python manage.py migrate
,它就会为特定字段提供以下错误(选项字段) )。
django.db.utils.DataError: value too long for type character varying(1)
字段所在的模型是:
models.py
class Api(models.Model):
User = get_user_model()
notice_name = models.CharField(max_length=100, null=True)
notice_desc = models.TextField()
notice_file = models.FileField(upload_to="notice_files/", null=True, blank=True)
notice_author = models.CharField(max_length=20, default='admin')
notice_valid_till = models.DateTimeField(default=datetime.now, blank=True)
notice_publish_date = models.DateTimeField(auto_now=True)
year = models.CharField(max_length=5, null=True)
branch = models.CharField(max_length=20, null=True)
choices = models.CharField(max_length=20, null=True)
user = models.ForeignKey('accounts.Account', on_delete=models.CASCADE, null=True)
我尝试改变choices
字段的长度,但它没有帮助。任何人都可以帮我解决这个问题。
修改
Running python3 manage.py migrate on ⬢ polar-caverns-67420... up, run.5910 (Free)
Operations to perform:
Apply all migrations: accounts, admin, api, auth, authtoken, contenttypes, feedback, sessions
Running migrations:
Applying accounts.0001_initial... OK
Applying accounts.0002_account_confirm_password... OK
Applying accounts.0003_auto_20171106_0842... OK
Applying accounts.0004_images... OK
Applying accounts.0005_auto_20171106_1137... OK
Applying accounts.0006_profile_user... OK
Applying accounts.0007_remove_profile_user... OK
Applying accounts.0008_profile_user... OK
Applying accounts.0009_auto_20171108_0637... OK
Applying accounts.0010_auto_20171108_0653... OK
Applying accounts.0011_auto_20171123_1608... OK
Applying accounts.0012_auto_20171123_1753... OK
Applying accounts.0013_auto_20171124_0258... OK
Applying accounts.0014_auto_20171124_0300... OK
Applying accounts.0015_profile_roll_no... OK
Applying contenttypes.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying api.0001_initial... OK
Applying api.0002_api_choices...Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.5/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
psycopg2.DataError: value too long for type character varying(1)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 204, in handle
fake_initial=fake_initial,
File "/app/.heroku/python/lib/python3.5/site-packages/django/db/migrations/executor.py", line 115, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/app/.heroku/python/lib/python3.5/site-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/app/.heroku/python/lib/python3.5/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/app/.heroku/python/lib/python3.5/site-packages/django/db/migrations/migration.py", line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/app/.heroku/python/lib/python3.5/site-packages/django/db/migrations/operations/fields.py", line 87, in database_forwards
field,
File "/app/.heroku/python/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 429, in add_field
self.execute(sql, params)
File "/app/.heroku/python/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 120, in execute
cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.5/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.5/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/app/.heroku/python/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/app/.heroku/python/lib/python3.5/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
django.db.utils.DataError: value too long for type character varying(1)