ValueError: Невозможно заключить в кавычки значение параметра [] типа <class 'list'> Django ArrayField - PullRequest
0 голосов
/ 03 сентября 2018

Хеллоу,

Хорошо, я попытался добавить 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',

Я действительно не знаю, что пошло не так, надеюсь, вы могли бы мне помочь.

1 Ответ

0 голосов
/ 17 января 2019

Вы используете PostgreSQL или sqlite3?

В вашем сообщении об ошибке пришла sqlite3. В django docs способ, которым вы можете использовать ArrayField, использует postgresql в качестве базы данных.

...