Opened 2 years ago

Closed 2 years ago

#34117 closed Bug (invalid)

Anomaly with makemigrations

Reported by: Ismael ABBO Owned by: nobody
Component: Migrations Version: 3.2
Severity: Normal Keywords: CustomUser, field, anomaly
Cc: Carsten Fuchs, Ed Chai Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Ismael ABBO)

Problem

Makemigrations command does not see the specific change on models related to this field below but produces migrations for any other fields (even in separated project):

gender = models.BooleanField(
	_('gender'),
	default=True,
	blank=True,
	help_text=_('Designates whether the user is a woman.'),
),

Adding in migration files works fine, but default value does not (while they're applied in ORM according to https://docs.djangoproject.com/en/4.1/ref/migration-operations/#addfield)
Then I have added blank=True to counter non-null constraint violation

When I add gender field in the migration files manually, executing makemigrations command again generate a delete of that field gender while I have not removed it in the associate model. Do we assume here that it does not see the field at all from the beginning?

When forcefully staying with that field, trying to run a command to populate database produces :

  File "/usr/local/lib/python3.9/site-packages/django/db/models/base.py", line 503, in __init__
    raise TypeError("%s() got an unexpected keyword argument '%s'" % (cls.__name__, kwarg))
TypeError: User() got an unexpected keyword argument 'gender'

Please, why? Am I wrong somewhere?

Steps to reproduce with my environment project (but optional because I have tried it in separated project aswell):

Change History (2)

comment:1 by Ismael ABBO, 2 years ago

Description: modified (diff)

comment:2 by Tim Graham, 2 years ago

Component: Database layer (models, ORM)Migrations
Resolution: invalid
Status: newclosed

You have a trailing comma after the field's closing parenthesis which creates a tuple and thus it isn't detected as a field. In the future, please see TicketClosingReasons/UseSupportChannels for ways to get help debugging and create a ticket only for confirmed bugs. Thanks!

Note: See TracTickets for help on using tickets.
Back to Top