Fix bug in database compatibility
This commit is contained in:
parent
f61bfc60d2
commit
19111af905
@ -120,7 +120,7 @@ ASGI_APPLICATION = "config.asgi.application"
|
|||||||
# so consider using postgresql instead
|
# so consider using postgresql instead
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
"default": {
|
"default": {
|
||||||
"ENGINE": "django.db.backends.postgresql_psycopg2",
|
"ENGINE": config("DB_ENGINE", default="django.db.backends.postgresql_psycopg2"),
|
||||||
"NAME": config("DB_NAME"),
|
"NAME": config("DB_NAME"),
|
||||||
"USER": config("DB_USER"),
|
"USER": config("DB_USER"),
|
||||||
"PASSWORD": config("DB_PASSWORD"),
|
"PASSWORD": config("DB_PASSWORD"),
|
||||||
|
|||||||
@ -1,8 +1,11 @@
|
|||||||
# Generated by Django 3.1.3 on 2021-04-16 09:14
|
# Generated by Django 3.1.3 on 2021-04-16 09:14
|
||||||
|
|
||||||
import django.contrib.postgres.fields
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
# Function to create initial data for array field in PostgreSQL
|
||||||
|
def create_array_field_for_postgres(apps, schema_editor):
|
||||||
|
TestClass = apps.get_model('payments', 'TestClass')
|
||||||
|
TestClass.objects.create(array=[])
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
@ -11,9 +14,12 @@ class Migration(migrations.Migration):
|
|||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
|
# Adding a JSONField for array, which is supported by both PostgreSQL and MySQL
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='testclass',
|
model_name='testclass',
|
||||||
name='array',
|
name='array',
|
||||||
field=django.contrib.postgres.fields.ArrayField(base_field=models.IntegerField(), blank=True, default=list, null=True, size=200),
|
field=models.JSONField(blank=True, default=list, null=True),
|
||||||
),
|
),
|
||||||
|
# Running the create_array_field_for_postgres function to populate initial data in PostgreSQL
|
||||||
|
migrations.RunPython(create_array_field_for_postgres),
|
||||||
]
|
]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user