Support Django 5.0 db_default attribute.
A DB default is not considered backward incompatible, as the default value is kept on DB-level. See https://docs.djangoproject.com/en/dev/releases/5.0/#database-computed-default-values
This commit is contained in:
1 parent
3a557cbd7c
commit
18a39cb3fc
12 files changed
+127
-13
No files matched your search
Whitespace-only changes.
+30
@@ -0,0 +1,30 @@
|
||||
# Generated by Django 5.0.1 on 2024-02-04 20:07
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = []
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="A",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("field", models.IntegerField()),
|
||||
],
|
||||
),
|
||||
]
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
# Generated by Django 5.0.1 on 2024-02-04 20:07
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import django.db.models.functions.math
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("app_add_not_null_column_followed_by_db_default", "0001_initial"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="a",
|
||||
name="not_null_field_db_default",
|
||||
field=models.IntegerField(db_default=django.db.models.functions.math.Pi()),
|
||||
),
|
||||
]
|
||||
Whitespace-only changes.
@@ -0,0 +1,12 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from django.db import models
|
||||
from django.db.models.functions import Pi
|
||||
|
||||
|
||||
class A(models.Model):
|
||||
field = models.IntegerField()
|
||||
not_null_field_db_default = models.IntegerField(
|
||||
null=False,
|
||||
db_default=Pi(),
|
||||
)
|
||||
@@ -14,6 +14,8 @@ from __future__ import annotations
|
||||
|
||||
import os
|
||||
|
||||
import django
|
||||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
@@ -59,6 +61,12 @@ INSTALLED_APPS = [
|
||||
"tests.test_project.app_create_index_exclusive",
|
||||
]
|
||||
|
||||
if django.VERSION[0] >= 5:
|
||||
# db_default attribute was only added in Django 5.0
|
||||
INSTALLED_APPS.append(
|
||||
"tests.test_project.app_add_not_null_column_followed_by_db_default"
|
||||
)
|
||||
|
||||
MIDDLEWARE = [
|
||||
"django.middleware.security.SecurityMiddleware",
|
||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||
|
||||
Reference in new issue
Block a user