Merge pull request #22 from WajahatKanju/bug/db-compatibility

Fix bug in database compatibility
This commit is contained in:
Adil Mohak 2024-02-05 15:03:58 +03:00 committed by GitHub
commit 789c827d00
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 3 deletions

View File

@ -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"),

View File

@ -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),
] ]