Hellow
好吧,我试图将ArrayField添加到我的一个模型中,但是当使用迁移时,出现此错误:
C:\Users\ordinateur\Documents\AAA\jeanclaude56>python manage.py migrate
System check identified some issues:
WARNINGS:
guide.Jeu.genre: (fields.W340) null has no effect on ManyToManyField.
guide.Jeu.missionsPrincipales: (postgres.E003) ArrayField default should be a callable instead of an instance so that it's not shared between all field instances.
HINT: Use a callable instead, e.g., use `list` instead of `[]`.
Operations to perform:
Apply all migrations: accueil, admin, auth, contenttypes, guide, sessions, thumbnail
Running migrations:
Applying guide.0011_jeu_missionsprincipales...Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Program Files (x86)\Python37-32\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\django\core\management\base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\django\core\management\base.py", line 353, in execute
output = self.handle(*args, **options)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\django\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\django\core\management\commands\migrate.py", line 203, in handle
fake_initial=fake_initial,
File "C:\Program Files (x86)\Python37-32\lib\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 "C:\Program Files (x86)\Python37-32\lib\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 "C:\Program Files (x86)\Python37-32\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\django\db\migrations\migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\django\db\migrations\operations\fields.py", line 84, in database_forwards
field,
File "C:\Program Files (x86)\Python37-32\lib\site-packages\django\db\backends\sqlite3\schema.py", line 300, in add_field
self._remake_table(model, create_field=field)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\django\db\backends\sqlite3\schema.py", line 172, in _remake_table
self.effective_default(create_field)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\django\db\backends\sqlite3\schema.py", line 56, in quote_value
raise ValueError("Cannot quote parameter value %r of type %s" % (value, type(value)))
ValueError: Cannot quote parameter value [] of type <class 'list'>
这是我的模型:
class Jeu(models.Model):
nom = models.CharField(max_length=60)
datesortie = models.DateField( null=True, blank = True, verbose_name='date de sortie' )
genre = models.ManyToManyField('Genre', null=True, blank = True )
solo = models.BooleanField()
multi = models.BooleanField()
censure = models.IntegerField(null=True, blank = True )
nomVO = models.CharField(max_length=60, null=True, blank = True )
developpeur = models.CharField(max_length=60, null=True, blank = True )
editeur = models.CharField(max_length=60, null=True, blank = True )
slug = models.SlugField(max_length=60)
photo = models.ImageField(upload_to="photos/jeu")
missionsPrincipales = ArrayField(models.CharField(max_length=50, blank=True), default = list() )
class Meta:
verbose_name ="jeu"
verbose_name_plural = "jeux"
def __str__(self):
return self.nom
Ps:我也尝试使用default = list(在错误消息中建议这样做,但它也不起作用) Makemigrations工作正常,我将这两个应用程序添加到设置中:“ django.contrib.postgres.fields”, 'psycopg2'
我真的不知道出了什么问题,希望您能帮助我。
答案 0 :(得分:0)
您使用的是PostgreSQL还是sqlite3?
在您的错误消息中,错误来自sqlite3。在django docs中,可以使用ArrayField的方式是将postgresql用作数据库。