diff options
author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-01-04 05:50:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-04 05:50:00 +0100 |
commit | 30613d6a748fce18919ff8b0da166d9fda2ed9bc (patch) | |
tree | a3ddfcff5c655e490e6c9d87cf53fa8e15b899a2 /django/db/backends/sqlite3/schema.py | |
parent | 0ab58c120939093fea90822f376e1866fc714d1f (diff) | |
download | django-30613d6a748fce18919ff8b0da166d9fda2ed9bc.tar.gz |
Fixed #33408 -- Fixed adding nullable unique fields on SQLite.
Regression in 2f73e5406d54cb8945e187eff302a3a3373350be.
Thanks Alan Crosswell for the report.
Diffstat (limited to 'django/db/backends/sqlite3/schema.py')
-rw-r--r-- | django/db/backends/sqlite3/schema.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/django/db/backends/sqlite3/schema.py b/django/db/backends/sqlite3/schema.py index 6752a8e3c0..3ff0a3f7db 100644 --- a/django/db/backends/sqlite3/schema.py +++ b/django/db/backends/sqlite3/schema.py @@ -324,10 +324,15 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): def add_field(self, model, field): """Create a field on a model.""" - # Fields with default values cannot by handled by ALTER TABLE ADD - # COLUMN statement because DROP DEFAULT is not supported in - # ALTER TABLE. - if not field.null or self.effective_default(field) is not None: + if ( + # Primary keys and unique fields are not supported in ALTER TABLE + # ADD COLUMN. + field.primary_key or field.unique or + # Fields with default values cannot by handled by ALTER TABLE ADD + # COLUMN statement because DROP DEFAULT is not supported in + # ALTER TABLE. + not field.null or self.effective_default(field) is not None + ): self._remake_table(model, create_field=field) else: super().add_field(model, field) |