#31688: Fail to rename and reuse field when using postgres
-----------------------------------------+------------------------
Reporter: Eran Keydar | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
The scenario is the following.
1. model with foreign key pointer point to Model1
2. pointer in rename to old_pointer ( + making rename migration)
3. 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
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31688>
Django <https://code.djangoproject.com/>
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 on the web visit
https://groups.google.com/d/msgid/django-updates/050.b8a467fdfc60843693cc5d1068e2f5f9%40djangoproject.com.