首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >添加阵列字段OperationalError

添加阵列字段OperationalError
EN

Stack Overflow用户
提问于 2018-06-11 22:30:16
回答 1查看 502关注 0票数 1

我对django(Version1.11)非常陌生,.I正试图创建一个购物网站,我对创建订单模型感到困惑。在这里,您可以看到我的第一个(版本1) models.py

代码语言:javascript
复制
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.contrib.postgres.fields import ArrayField


class Products(models.Model):
    name = models.CharField(max_length = 20 , default='')
    description = models.CharField(max_length = 100 , default='')
    price = models.IntegerField(default=0)
    image = models.ImageField(upload_to='product_image',blank=True)
    vojood = models.BooleanField(default=False)
    unique = models.CharField(max_length = 100 ,default='')
    typ = models.CharField(max_length = 100 ,default='')
    def __str__ (self):
        return self.name
    @classmethod
    def turn_on(prds,pk):
        prds[pk].vojood=true

    @classmethod
    def turn_off(prds,pk):
        prds[pk].vojood=false
class Order(models.Model):
    username = models.CharField(max_length = 300 , default='')
    address = models.CharField(max_length = 300 , default='')
    time = models.IntegerField(default=0)
    price = models.IntegerField(default=0)
    arrived = models.BooleanField(default=False)
    basket = ArrayField(models.CharField(max_length=300,default=''),default=list)
    def __str__ (self):
        return self.username

python manage.py makemigrations之后,当我试图用python manage.py migrate迁移新字段(arrayfield)时,我得到了一个非常长的错误。所以最后一行是django.db.utils.OperationalError: near "[]": syntax error,所以我删除了新字段(Arrayfield),再次使用了makemigrations,但是迁移过程中的错误没有change.And,现在我不能迁移任何类型的字段!这是我的错误:

代码语言:javascript
复制
E:\django projects\4\third>python manage.py makemigrations
Migrations for 'shop':
  shop\migrations\0013_auto_20180611_1518.py
    - Alter field basket on order

E:\django projects\4\third>python manage.py migrate
Operations to perform:
  Apply all migrations: accounts, admin, auth, contenttypes, sessions, shop
Running migrations:
  Applying shop.0005_order_prds...Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 63, in
execute
    return self.cursor.execute(sql)
  File "C:\Python34\lib\site-packages\django\db\backends\sqlite3\base.py", line
326, in execute
    return Database.Cursor.execute(self, query)
sqlite3.OperationalError: near "[]": syntax error

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 "C:\Python34\lib\site-packages\django\core\management\__init__.py", line
364, in execute_from_command_line
    utility.execute()
  File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line
356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python34\lib\site-packages\django\core\management\base.py", line 283,
 in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Python34\lib\site-packages\django\core\management\base.py", line 330,
 in execute
    output = self.handle(*args, **options)
  File "C:\Python34\lib\site-packages\django\core\management\commands\migrate.py
", line 204, in handle
    fake_initial=fake_initial,
  File "C:\Python34\lib\site-packages\django\db\migrations\executor.py", line 11
5, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_i
nitial=fake_initial)
  File "C:\Python34\lib\site-packages\django\db\migrations\executor.py", line 14
5, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_
initial)
  File "C:\Python34\lib\site-packages\django\db\migrations\executor.py", line 24
4, in apply_migration
    state = migration.apply(state, schema_editor)
  File "C:\Python34\lib\site-packages\django\db\migrations\migration.py", line 1
29, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, projec
t_state)
  File "C:\Python34\lib\site-packages\django\db\migrations\operations\fields.py"
, line 87, in database_forwards
    field,
  File "C:\Python34\lib\site-packages\django\db\backends\sqlite3\schema.py", lin
e 238, in add_field
    self._remake_table(model, create_field=field)
  File "C:\Python34\lib\site-packages\django\db\backends\sqlite3\schema.py", lin
e 198, in _remake_table
    self.create_model(temp_model)
  File "C:\Python34\lib\site-packages\django\db\backends\base\schema.py", line 3
03, in create_model
    self.execute(sql, params or None)
  File "C:\Python34\lib\site-packages\django\db\backends\base\schema.py", line 1
20, in execute
    cursor.execute(sql, params)
  File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 80, in
execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 65, in
execute
    return self.cursor.execute(sql, params)
  File "C:\Python34\lib\site-packages\django\db\utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "C:\Python34\lib\site-packages\django\utils\six.py", line 685, in reraise

    raise value.with_traceback(tb)
  File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 63, in
execute
    return self.cursor.execute(sql)
  File "C:\Python34\lib\site-packages\django\db\backends\sqlite3\base.py", line
326, in execute
    return Database.Cursor.execute(self, query)
django.db.utils.OperationalError: near "[]": syntax error

E:\django projects\4\third>

我还将数组字段的名称从prds更改为basket,但是在错误中可以看到名称没有更改!尽管上一次创建的迁移是00013_etc,但它仍然运行着00013_etc!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-12 20:43:40

我认为您的问题是您使用的是SQLite数据库,您需要使用Postgres数据库- see this similar question.

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50806927

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档