diff --git a/config/settings.py b/config/settings.py index 8073185..13d9819 100644 --- a/config/settings.py +++ b/config/settings.py @@ -120,7 +120,7 @@ ASGI_APPLICATION = "config.asgi.application" # so consider using postgresql instead DATABASES = { "default": { - "ENGINE": "django.db.backends.postgresql_psycopg2", + "ENGINE": config("DB_ENGINE", default="django.db.backends.postgresql_psycopg2"), "NAME": config("DB_NAME"), "USER": config("DB_USER"), "PASSWORD": config("DB_PASSWORD"), diff --git a/payments/migrations/0002_testclass_array.py b/payments/migrations/0002_testclass_array.py index d8296ed..250e2d8 100644 --- a/payments/migrations/0002_testclass_array.py +++ b/payments/migrations/0002_testclass_array.py @@ -1,8 +1,11 @@ # Generated by Django 3.1.3 on 2021-04-16 09:14 -import django.contrib.postgres.fields 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): @@ -11,9 +14,12 @@ class Migration(migrations.Migration): ] operations = [ + # Adding a JSONField for array, which is supported by both PostgreSQL and MySQL migrations.AddField( model_name='testclass', 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), ]