28π
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)
1π
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.
- How to I hide my secret_key using virtualenv and Django?
- Django: "order" a queryset based on a boolean field
- How do I convert a django QuerySet to numpy record array?
- PyCharm β Unresolved library 'staticfiles'
- How to convert a list of dictionaries to JSON in Python / Django?
1π
The fix is to simply remove the new migration files which has not been applied. You can see those by running the command.
python manage.py showmigrations
The files against which the βtickβ is absent are the ones that can be safely removed. Once removed, then go to the models.py and remove the ArrayField
field.
Run the makemigrations
command again followed by the migrate
command. This time it should work.
If you want to use the ArrayField
field then you should use postgres database in your project.
- How to use Datepicker in django
- ModelViewSet β Update nested field
- Is the Global Request variable in Python/Django available?
- Is not JSON serializable β django social auth Facebook login
- Django is very slow on my machine
0π
The ArrayField
docs warn that you shouldnβt use a mutable value like []
. You can use the callable list
for an empty default.
class Test(models.Model):
...
mark3=ArrayField(models.CharField(max_length=5), default=list)
mark4=ArrayField(models.CharField(max_length=5), default=list)
mark7=ArrayField(models.CharField(max_length=5), default=list)
After making this change, delete the old migration file and run makemigrations
again.
- Django form with multiple file fields
- Django docker β could not translate host name "db" to address: nodename nor servname provided, or not known
- Using existing field values in django update query
- How to store django objects as session variables ( object is not JSON serializable)?