Re: [Django] #37006: Attempting to recreate the PK in a model with no other fields generates a migration that crashes on SQLite

2026-04-20 Thread Django
#37006: Attempting to recreate the PK in a model with no other fields generates 
a
migration that crashes on SQLite
-+-
 Reporter:  Carol Naranjo|Owner:  Carol
 |  Naranjo
 Type:  Bug  |   Status:  assigned
Component:  Migrations   |  Version:  6.0
 Severity:  Normal   |   Resolution:
 Keywords:  sqlite, migrations   | Triage Stage:  Accepted
Has patch:  1|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  1
Easy pickings:  0|UI/UX:  0
-+-
Comment (by Carol Naranjo):

 hi Simon, sorry for the slow updates (life in between). I updated the PR
 again according to your remarks, I hope the changes are clear, let me know
 :)
-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019daa58b76a-9f680698-5217-4007-b42c-5ada0e7d01a0-00%40eu-central-1.amazonses.com.


Re: [Django] #37006: Attempting to recreate the PK in a model with no other fields generates a migration that crashes on SQLite

2026-04-12 Thread Django
#37006: Attempting to recreate the PK in a model with no other fields generates 
a
migration that crashes on SQLite
-+-
 Reporter:  Carol Naranjo|Owner:  Carol
 |  Naranjo
 Type:  Bug  |   Status:  assigned
Component:  Migrations   |  Version:  6.0
 Severity:  Normal   |   Resolution:
 Keywords:  sqlite, migrations   | Triage Stage:  Accepted
Has patch:  1|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  1
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Simon Charette):

 * needs_better_patch:  0 => 1

Comment:

 Thanks for the patch Carol, excited to hear you are part of Djangonauts!

 I left some comments on the PR. It is heading in the right direction but
 it should offer the possibility of a rename and not force it when a
 primary is changed because we won't be able to support all field type
 alterations so we need an escape hatch to allow the users to drop the
 field and create a new one when it's the case.
-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019d8206d1fa-80482860-f2b1-48ba-be74-e7aba64602d1-00%40eu-central-1.amazonses.com.


Re: [Django] #37006: Attempting to recreate the PK in a model with no other fields generates a migration that crashes on SQLite

2026-04-08 Thread Django
#37006: Attempting to recreate the PK in a model with no other fields generates 
a
migration that crashes on SQLite
-+-
 Reporter:  Carol Naranjo|Owner:  Carol
 |  Naranjo
 Type:  Bug  |   Status:  assigned
Component:  Migrations   |  Version:  6.0
 Severity:  Normal   |   Resolution:
 Keywords:  sqlite, migrations   | Triage Stage:  Accepted
Has patch:  1|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Comment (by Carol Naranjo):

 By the way, regarding the PR tags, it might be worth mentioning that I’m
 part of the current Djangonauts cohort
-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019d6d5687b3-db6b4247-4e00-406d-a9e9-09b361e2c59d-00%40eu-central-1.amazonses.com.


Re: [Django] #37006: Attempting to recreate the PK in a model with no other fields generates a migration that crashes on SQLite

2026-04-08 Thread Django
#37006: Attempting to recreate the PK in a model with no other fields generates 
a
migration that crashes on SQLite
-+-
 Reporter:  Carol Naranjo|Owner:  Carol
 |  Naranjo
 Type:  Bug  |   Status:  assigned
Component:  Migrations   |  Version:  6.0
 Severity:  Normal   |   Resolution:
 Keywords:  sqlite, migrations   | Triage Stage:  Accepted
Has patch:  1|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Simon Charette):

 * cc: Simon Charette (added)

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019d6d157320-0ad015ef-e180-4835-b785-26b7f574fdc8-00%40eu-central-1.amazonses.com.


Re: [Django] #37006: Attempting to recreate the PK in a model with no other fields generates a migration that crashes on SQLite

2026-04-08 Thread Django
#37006: Attempting to recreate the PK in a model with no other fields generates 
a
migration that crashes on SQLite
-+-
 Reporter:  Carol Naranjo|Owner:  Carol
 |  Naranjo
 Type:  Bug  |   Status:  assigned
Component:  Migrations   |  Version:  6.0
 Severity:  Normal   |   Resolution:
 Keywords:  sqlite, migrations   | Triage Stage:  Accepted
Has patch:  1|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Carol Naranjo):

 * has_patch:  0 => 1

Comment:

 Hello Jacob, Simon, I'm back after a short holiday break, happy Easter!

 I have now created a PR ready for review here:
 https://github.com/django/django/pull/21073 . Let me know if something is
 missing. Thanks!
-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019d6cfda581-8b99a7c5-62ec-456d-99dc-f121aca3b026-00%40eu-central-1.amazonses.com.


[Django] #37006: Attempting to recreate the PK in a model with no other fields generates a migration that crashes on SQLite

2026-03-26 Thread Django
#37006: Attempting to recreate the PK in a model with no other fields generates 
a
migration that crashes on SQLite
-+-
 Reporter:  Carol Naranjo| Type:  Bug
   Status:  new  |Component:  Database
 |  layer (models, ORM)
  Version:  6.0  | Severity:  Normal
 Keywords:  sqlite, migrations   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
 When a model contains no fields other than the primary key, and the PK is
 recreated (e.g., renaming and switching from an AutoField to a UUIDField),
 Django generates a migration with two operations: RemoveField followed by
 AddField.

 In SQLite, applying this migration fails because SQLite cannot create a
 table with no columns. It only affects SQLite because in other databases
 the table can be altered by droping the column, whereas SQLite requires
 that a new table is created and then the data is copied.

 **Steps to reproduce:**

 1. Starting with a model with only the primary key:
 {{{
 class Place(models.Model):
 pass # PK is created by default as AutoField with column name "id"
 }}}

 2. Modify the primary key:
 {{{
 class Place(models.Model):
 uuid = models.UUIDField(primary_key=True, default=uuid.uuid4,
 editable=False)
 }}}

 3. Run `makemigrations`. Which generates following migration:

 {{{

 class Migration(migrations.Migration):

 dependencies = [
 ('myapp', '0001_initial'),
 ]

 operations = [
 migrations.RemoveField(
 model_name='place',
 name='id',
 ),
 migrations.AddField(
 model_name='place',
 name='uid',
 field=models.AutoField(primary_key=True, serialize=False),
 ),
 ]
 }}}


 4. Apply the migration using SQLite.

 **Observed behavior:**

 During the RemoveField operation, the generated migration tries to create
 a table with zero non-PK columns, resulting in:

 {{{
 CREATE TABLE "new__myapp_place" (); (params None)
 sqlite3.OperationalError: near ")": syntax error
 }}}


 **Expected behavior:**

 SQLite migration should not crash. Either prevent a migration that would
 create a table with zero columns or handle it gracefully.

 **On a side note**: This is an edge case—tables without additional fields
 are rare—but it still causes an unexpected crash.
-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019d2abbd410-be5fefc2-4ba1-4231-99d9-8cb682f0703e-00%40eu-central-1.amazonses.com.


Re: [Django] #37006: Attempting to recreate the PK in a model with no other fields generates a migration that crashes on SQLite

2026-03-26 Thread Django
#37006: Attempting to recreate the PK in a model with no other fields generates 
a
migration that crashes on SQLite
-+-
 Reporter:  Carol Naranjo|Owner:  Carol
 |  Naranjo
 Type:  Bug  |   Status:  assigned
Component:  Migrations   |  Version:  6.0
 Severity:  Normal   |   Resolution:
 Keywords:  sqlite, migrations   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Comment (by Carol Naranjo):

 @Jacob, ah got you, thanks for the clarification :)

 Thanks for the hint Simon!
-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019d2b37cd63-07f48b5f-0e4c-4d2d-b0f5-8b3a9f778644-00%40eu-central-1.amazonses.com.


Re: [Django] #37006: Attempting to recreate the PK in a model with no other fields generates a migration that crashes on SQLite

2026-03-26 Thread Django
#37006: Attempting to recreate the PK in a model with no other fields generates 
a
migration that crashes on SQLite
-+-
 Reporter:  Carol Naranjo|Owner:  Carol
 |  Naranjo
 Type:  Bug  |   Status:  assigned
Component:  Migrations   |  Version:  6.0
 Severity:  Normal   |   Resolution:
 Keywords:  sqlite, migrations   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Comment (by Simon Charette):

 Sure thing Carol, please assign the ticket to yourself and take some time
 to read [https://docs.djangoproject.com/en/6.0/internals/contributing/ the
 contribution guidelines].

 You'll like be looking at code living in `autodetector.py` and associated
 tests in `tests/migrations/test_autodetector.py`.
-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019d2b29e873-5741b900-5195-403e-a878-31b6d0592dfb-00%40eu-central-1.amazonses.com.


Re: [Django] #37006: Attempting to recreate the PK in a model with no other fields generates a migration that crashes on SQLite

2026-03-26 Thread Django
#37006: Attempting to recreate the PK in a model with no other fields generates 
a
migration that crashes on SQLite
-+-
 Reporter:  Carol Naranjo|Owner:  Carol
 |  Naranjo
 Type:  Bug  |   Status:  assigned
Component:  Migrations   |  Version:  6.0
 Severity:  Normal   |   Resolution:
 Keywords:  sqlite, migrations   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Jacob Walls):

 * owner:  (none) => Carol Naranjo
 * status:  new => assigned

Comment:

 Oh it's definitely unrelated. I wasn't blaming that commit, I was just
 leaving a reference in case it's retriaged a few years from now and we
 can't reproduce.

 > If it’s not time-sensitive, I’d be happy to work on a fix and assign the
 ticket to myself.

 Not time-sensitive, thanks for the offer!
-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019d2b29643d-64a9863a-d580-4580-81bb-9da2982271cb-00%40eu-central-1.amazonses.com.


Re: [Django] #37006: Attempting to recreate the PK in a model with no other fields generates a migration that crashes on SQLite

2026-03-26 Thread Django
#37006: Attempting to recreate the PK in a model with no other fields generates 
a
migration that crashes on SQLite
+
 Reporter:  Carol Naranjo   |Owner:  (none)
 Type:  Bug |   Status:  new
Component:  Migrations  |  Version:  6.0
 Severity:  Normal  |   Resolution:
 Keywords:  sqlite, migrations  | Triage Stage:  Accepted
Has patch:  0   |  Needs documentation:  0
  Needs tests:  0   |  Patch needs improvement:  0
Easy pickings:  0   |UI/UX:  0
+
Comment (by Carol Naranjo):

 Replying to [comment:1 Jacob Walls]:
 > Thanks, reproduced at f6167b8bc881babd19b67c004e8f37954afc192e. Looks
 like another circumstance that manifests the failure described in #24424.
 Hi Jacob, can you double check the commit link? it seems unrelated.

 ---

 Replying to [comment:2 Simon Charette]:
 >
 > There might be a way to approach this at the auto-detector level by
 turning a removal and addition of a `Field(primary_key=True)` with a
 different name as a `[AlterField, RenameField]` instead of a
 `[RemoveField, AddField]`.

 Hi Simon, I like that approach. If it’s not time-sensitive, I’d be happy
 to work on a fix and assign the ticket to myself.
-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019d2b25f0a2-e80c0637-03ae-4a47-a393-b968604e131c-00%40eu-central-1.amazonses.com.


Re: [Django] #37006: Attempting to recreate the PK in a model with no other fields generates a migration that crashes on SQLite

2026-03-26 Thread Django
#37006: Attempting to recreate the PK in a model with no other fields generates 
a
migration that crashes on SQLite
+
 Reporter:  Carol Naranjo   |Owner:  (none)
 Type:  Bug |   Status:  new
Component:  Migrations  |  Version:  6.0
 Severity:  Normal  |   Resolution:
 Keywords:  sqlite, migrations  | Triage Stage:  Accepted
Has patch:  0   |  Needs documentation:  0
  Needs tests:  0   |  Patch needs improvement:  0
Easy pickings:  0   |UI/UX:  0
+
Changes (by Jacob Walls):

 * component:  Database layer (models, ORM) => Migrations
 * stage:  Unreviewed => Accepted

Comment:

 Thanks, reproduced at f6167b8bc881babd19b67c004e8f37954afc192e. Looks like
 another circumstance that manifests the failure described in #24424.
-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019d2ad3dde5-075ac192-3e55-4bfd-85f1-b35d6a0fa282-00%40eu-central-1.amazonses.com.


Re: [Django] #37006: Attempting to recreate the PK in a model with no other fields generates a migration that crashes on SQLite

2026-03-26 Thread Django
#37006: Attempting to recreate the PK in a model with no other fields generates 
a
migration that crashes on SQLite
+
 Reporter:  Carol Naranjo   |Owner:  (none)
 Type:  Bug |   Status:  new
Component:  Migrations  |  Version:  6.0
 Severity:  Normal  |   Resolution:
 Keywords:  sqlite, migrations  | Triage Stage:  Accepted
Has patch:  0   |  Needs documentation:  0
  Needs tests:  0   |  Patch needs improvement:  0
Easy pickings:  0   |UI/UX:  0
+
Comment (by Simon Charette):

 Related tickets are #22997 and #29790.

 The way SQLite [https://sqlite.org/lang_altertable.html requires the table
 to be rebuilt on field removal and alterations] would likely force us to
 add a `_django_empty_col` column to support this workflow.

 There might be a way to approach this at the auto-detector level by
 turning a removal and addition of a `Field(primary_key=True)` with a
 different name as a `[AlterField, RenameField]` instead of a
 `[RemoveField, AddField]`. Since a model/table can only have one primary
 key at a time that seems like a better way to approach this problem as it
 would then allow us to focus our efforts on getting `AlterField(from_pk,
 to_pk)` to work in most cases which is what #29790 is about.
-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019d2af6bd8f-934c45bc-4c8b-4fb4-80d3-906d40891345-00%40eu-central-1.amazonses.com.