Opened 5 years ago
Closed 5 years ago
#31688 closed Bug (duplicate)
Fail to rename and reuse field when using postgres
Reported by: | Eran Keydar | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | 3.0 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The scenario is the following.
- model with foreign key pointer point to Model1
- pointer in rename to old_pointer ( + making rename migration)
- adding pointer again but not points to Model2
getting an error that index is already exists.
This fails on Postgres, when working with sqlite it is ok.
Below is the relevant code:
Step 1:
class Model1(models.Model): name = models.CharField(max_length=30) class Model2(models.Model): name2 = models.CharField(max_length=30) class MainModel(models.Model): pointer = models.ForeignKey(Model1, null=True, on_delete=models.CASCADE)
Then running makemigrations + migrate.
Step 2:
Changing the pointer to old_pointer then running makemigrations + migrate (+ yes for the rename question)
class MainModel(models.Model): old_pointer = models.ForeignKey(Model1, null=True, on_delete=models.CASCADE)
Step 3:
Adding back the pointer field, now to Model2
class MainModel(models.Model): old_pointer = models.ForeignKey(Model1, null=True, on_delete=models.CASCADE) pointer = models.ForeignKey(Model2, null=True, on_delete=models.CASCADE)
running makemigrations and then migrate yields the following error:
return self.cursor.execute(sql, params) psycopg2.errors.DuplicateTable: relation "app1_mainmodel_pointer_id_c7a78539" already exists
Change History (1)
comment:1 by , 5 years ago
Component: | Uncategorized → Migrations |
---|---|
Resolution: | → duplicate |
Status: | new → closed |
Type: | Uncategorized → Bug |
Note:
See TracTickets
for help on using tickets.
Duplicate of #23577.