django.db.utils.OperationalError: near "[]": syntax error
I puzzled over this one for a little while too. The ArrayField is specific to Postgres, and is imported from a Postgres library:
import django.contrib.postgres.fields
It looks like you're trying to commit your migrations to SQLite. You should set up a local Postgres database, and update your settings.py
file from:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
To:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'DATABASE NAME',
'USER': 'USER NAME',
'PASSWORD': 'USER PASSWORD',
'HOST': 'localhost',
'PORT': '5432',
}
}
Also, you are incorrectly setting the default value for your ArrayField. Per Django ArrayField documentation, you should not use [] as the default. It won't cause this problem, but it will probably create some others! You should use default=list
instead of default=[]
, which will create a mutable default shared between all instances of ArrayField:
Instead of:
mark7=ArrayField(models.CharField(max_length=5),default=[])
Try:
mark7=ArrayField(models.CharField(max_length=5),default=list)
I stupidly used this specific posgresql field - ArrayField for the model and let the test run with sqlite. That caused the error when I pushed code to github with the travis-ci.