Comment (by David Sanders):
Looks like felix already narrowed it down but here's a failing test case
just in case someone can use it:
{{{
--- a/tests/migrations/test_operations.py
+++ b/tests/migrations/test_operations.py
@@ -5801,6 +5801,36 @@ class OperationTests(OperationTestBase):
def test_remove_generated_field_virtual(self):
self._test_remove_generated_field(db_persist=False)
+ @skipUnlessDBFeature("supports_stored_generated_columns")
+ def test_add_field_after_generated_field(self):
+ app_label = "test_adfagf"
+ project_state = self.set_up_test_model(app_label)
+ operation_1 = migrations.AddField(
+ "Pony",
+ "generated",
+ models.GeneratedField(
+ expression=Value(1),
+ output_field=models.IntegerField(),
+ db_persist=True,
+ ),
+ )
+ operation_2 = migrations.AddField(
+ "Pony",
+ "static",
+ models.IntegerField(default=2),
+ )
+ new_state = project_state.clone()
+ operation_1.state_forwards(app_label, new_state)
+ with connection.schema_editor() as editor:
+ operation_1.database_forwards(app_label, editor,
project_state, new_state)
+ project_state, new_state = new_state, new_state.clone()
+ operation_2.state_forwards(app_label, new_state)
+ with connection.schema_editor() as editor:
+ operation_2.database_forwards(app_label, editor,
project_state, new_state)
+ pony = new_state.apps.get_model(app_label,
"Pony").objects.create(weight=20)
+ self.assertEqual(pony.generated, 1)
+ self.assertEqual(pony.static, 2)
+
class SwappableOperationTests(OperationTestBase):
"""
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34984#comment:12>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by Mariusz Felisiak):
I think it's enough to skip `GeneratedField`s when remaking tables on
SQLite:
{{{#!diff
diff --git a/django/db/backends/sqlite3/schema.py
b/django/db/backends/sqlite3/schema.py
index a8200a1a8c..713ef31437 100644
--- a/django/db/backends/sqlite3/schema.py
+++ b/django/db/backends/sqlite3/schema.py
@@ -106,7 +106,7 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
# its values must be already quoted.
mapping = {
f.column: self.quote_name(f.column)
- for f in model._meta.local_concrete_fields
+ for f in model._meta.local_concrete_fields if f.generated is
False
}
# This maps field names (not columns) for things like
unique_together
rename_mapping = {}
}}}
Sarah, would you like to prepare a patch?
--
Ticket URL: <https://code.djangoproject.com/ticket/34984#comment:13>
Comment (by Sarah Boyce):
I can tomorrow, if anyone wants to pick it up sooner that's also fine 🙂
--
Ticket URL: <https://code.djangoproject.com/ticket/34984#comment:14>
* owner: nobody => Sarah Boyce
* status: new => assigned
Comment:
Replying to [comment:14 Sarah Boyce]:
> I can tomorrow, if anyone wants to pick it up sooner that's also fine 🙂
No rush, we can wait until tomorrow.
--
Ticket URL: <https://code.djangoproject.com/ticket/34984#comment:15>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/34984#comment:16>
* stage: Accepted => Ready for checkin
Comment:
[https://github.com/django/django/pull/17505 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/34984#comment:17>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"828082dad954e87d09a99b53424e6faa1860ccc7" 828082da]:
{{{
#!CommitTicketReference repository=""
revision="828082dad954e87d09a99b53424e6faa1860ccc7"
Fixed #34984 -- Skipped GeneratedFields when remaking tables on SQLite.
Regression in f333e3513e8bdf5ffeb6eeb63021c230082e6f95.t
Co-authored-by: Mariusz Felisiak <felisiak...@gmail.com>
Co-authored-by: David Sanders <shang.xia...@gmail.com>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34984#comment:18>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"0c6ca522263b0f5c4075b3634d7e5507d9528b52" 0c6ca522]:
{{{
#!CommitTicketReference repository=""
revision="0c6ca522263b0f5c4075b3634d7e5507d9528b52"
[5.0.x] Fixed #34984 -- Skipped GeneratedFields when remaking tables on
SQLite.
Regression in f333e3513e8bdf5ffeb6eeb63021c230082e6f95.t
Co-authored-by: Mariusz Felisiak <felisiak...@gmail.com>
Co-authored-by: David Sanders <shang.xia...@gmail.com>
Backport of 828082dad954e87d09a99b53424e6faa1860ccc7 from main
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34984#comment:19>