Django迁移错误

时间:2018-03-24 17:15:38

标签: django django-models terminal psycopg2

将Psycopg2 == 2.7.4导入我的服务器后,我无法再正常运行我的服务器了。添加新字段后,每当我尝试在makemigrations之后进行迁移(python manage.py migrate)时,我的终端就会发生这种情况:



 Apply all migrations: admin, auth, buddysapp, contenttypes, oauth2_provider, sessions, social_django
Running migrations:
  Applying buddysapp.0038_auto_20180321_0025...Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/hsi/Desktop/myvirtualenv/buddys/lib/python3.6/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/Users/hsi/Desktop/myvirtualenv/buddys/lib/python3.6/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/hsi/Desktop/myvirtualenv/buddys/lib/python3.6/site-packages/django/core/management/base.py", line 305, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/hsi/Desktop/myvirtualenv/buddys/lib/python3.6/site-packages/django/core/management/base.py", line 356, in execute
    output = self.handle(*args, **options)
  File "/Users/hsi/Desktop/myvirtualenv/buddys/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 202, in handle
    targets, plan, fake=fake, fake_initial=fake_initial
  File "/Users/hsi/Desktop/myvirtualenv/buddys/lib/python3.6/site-packages/django/db/migrations/executor.py", line 97, in migrate
    state = self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/Users/hsi/Desktop/myvirtualenv/buddys/lib/python3.6/site-packages/django/db/migrations/executor.py", line 132, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/Users/hsi/Desktop/myvirtualenv/buddys/lib/python3.6/site-packages/django/db/migrations/executor.py", line 237, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/Users/hsi/Desktop/myvirtualenv/buddys/lib/python3.6/site-packages/django/db/migrations/migration.py", line 129, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/Users/hsi/Desktop/myvirtualenv/buddys/lib/python3.6/site-packages/django/db/migrations/operations/fields.py", line 84, in database_forwards
    field,
  File "/Users/hsi/Desktop/myvirtualenv/buddys/lib/python3.6/site-packages/django/db/backends/sqlite3/schema.py", line 231, in add_field
    self._remake_table(model, create_fields=[field])
  File "/Users/hsi/Desktop/myvirtualenv/buddys/lib/python3.6/site-packages/django/db/backends/sqlite3/schema.py", line 113, in _remake_table
    self.effective_default(field)
  File "/Users/hsi/Desktop/myvirtualenv/buddys/lib/python3.6/site-packages/django/db/backends/sqlite3/schema.py", line 68, in quote_value
    raise ValueError("Cannot quote parameter value %r of type %s" % (value, type(value)))
ValueError: Cannot quote parameter value <psycopg2._json.Json object at 0x10ea5e748> of type <class 'psycopg2._json.Json'>
&#13;
&#13;
&#13;

任何想法,请告诉我。

更新:迁移文件0038

&#13;
&#13;
rom __future__ import unicode_literals

import buddysapp.models
import django.contrib.postgres.fields.jsonb
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('buddysapp', '0037_auto_20180318_1816'),
    ]

    operations = [
        migrations.AddField(
            model_name='dispensary',
            name='businessHours',
            field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, default=buddysapp.models.business_hours_default, null=True),
        ),
        migrations.AlterField(
            model_name='order',
            name='status',
            field=models.IntegerField(choices=[(1, 'Your Order Is Being Picked Right Off The Plant!'), (2, 'Picked, Weighed, And Ready For Delivery.'), (3, 'The Best Bud Is Heading Straight To Your Door.'), (4, 'Delivered'), (0, 'Canceled/Refunded')]),
        ),
    ]
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:3)

您不能将np.Point, np.Valid = Point{}, false 中的JSONField与Sqlite3数据库一起使用。

您需要设置PostgreSQL数据库并更新django.contrib.postgres设置,或在模型中使用其他字段。