Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UUIDField ignores primary_key=False when generating migrations or SQL #518

Open
xjlin0 opened this issue Feb 24, 2022 · 1 comment
Open

Comments

@xjlin0
Copy link

xjlin0 commented Feb 24, 2022

Problem

UUIDField with the option of primary_key=False got reverted to primary_key=True in generated migrations or SQL.

Environment

  • Django Model Utils version: 4.2.0
  • Django version: 3.2.11
  • Python version: cPython 3.9.10
  • Other libraries used, if any: with Cookie cutter Django version 2021-10-26

Code examples

Including a UUIDField with primary_key=False in a model:

test = model_utils.fields.UUIDField(primary_key=False, default=uuid.uuid4, editable=False, serialize=False)

Surprisingly, when running migration it becomes primary_key=True:

field=model_utils.fields.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, serialize=False)

as well as generated SQL:

CREATE TABLE table_name ("test" uuid NOT NULL PRIMARY KEY ....

If the model already got primary key column, it's a headache to find workaround.

Expectation

UUIDField with the option of primary_key=False should keep primary_key=False in generated migrations or SQL.

@timjnz
Copy link

timjnz commented Oct 24, 2022

Can confirm - I'm getting the same problem

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

No branches or pull requests

2 participants