Skip to content

[Junie]: Junie inspectdb creates a redundant unique_together for composite primary keys#6

Open
junie-eap[bot] wants to merge 1 commit intomainfrom
junie-issue-3
Open

[Junie]: Junie inspectdb creates a redundant unique_together for composite primary keys#6
junie-eap[bot] wants to merge 1 commit intomainfrom
junie-issue-3

Conversation

@junie-eap
Copy link
Copy Markdown

@junie-eap junie-eap bot commented Apr 28, 2025

📌 Hey! This PR was made for you with Junie, the coding agent by JetBrains Early Access Preview

It's still learning, developing, and might make mistakes. Please make sure you review the changes before you accept them.
We’d love your feedback — join our Discord to share bugs, ideas: here.

📝 Original Issue Description

  Issue task:
  Description 

With the following table:

CREATE TABLE example (
a integer,
b integer,
c integer,
PRIMARY KEY (a, c)
);
Running inspectdb produces the following model definition:

class Example(models.Model):
pk = models.CompositePrimaryKey('a', 'c')
a = models.IntegerField()
b = models.IntegerField(blank=True, null=True)
c = models.IntegerField()

class Meta:
    managed = False
    db_table = 'example'
    unique_together = (('a', 'c'),)

I'm pretty sure the last unique_together = (('a', 'c'),) is redundant since the pk = models.CompositePrimaryKey('a', 'c') already implies uniqueness, no?

  Issue comments:
  No comments yet

📊 Junie Summary

The inspectdb command in Django was modified to prevent redundant unique_together constraints for models with composite primary keys. The implementation was successful, ensuring correct handling of unique constraints, with all tests passing.

… composite primary keys

 changes from the task: #3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants