Opened 3 years ago

Closed 2 years ago

#21896 closed Cleanup/optimization (worksforme)

makemigrations warning "trying to add a non-nullable field" is raised even when the table is empty

Reported by: Lucio Asnaghi Owned by:
Component: Migrations Version: 1.7-alpha-1
Severity: Normal Keywords: migrations
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Probably doing a count() on the table would save a warning and user interaction.

Change History (6)

comment:1 Changed 3 years ago by anonymous

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

I don't think we can silence the warning in that case since it may be empty in dev, but then when you come to apply the migration in production it might not work. Much safer to always warn to make sure you've considered the possibility, as long as there's a way to ignore it if you're sure it'll be fine.

comment:2 Changed 3 years ago by Aymeric Augustin

I agree with the first comment: this sounds fragile. I'm leaving the final say to Andrew.

comment:3 Changed 3 years ago by Andrew Godwin

Resolution: invalid
Status: newclosed

We don't know what size the table might be in the future, so we have to raise this during makemigrations; you might make the migration on a dev box with no entries and then run it on a production box with millions of rows, so it has to stay. Marking INVALID.

comment:4 in reply to:  3 Changed 2 years ago by Ashish1206

Replying to andrewgodwin:

We don't know what size the table might be in the future, so we have to raise this during makemigrations; you might make the migration on a dev box with no entries and then run it on a production box with millions of rows, so it has to stay. Marking INVALID.

I am using django 1.7 and getting the same warning for fields when I use makemigrations on dev server.How to fix this?

After deleting the previous models and again using makemigrations it works now.I don't know what happened!

Last edited 2 years ago by Ashish1206 (previous) (diff)

comment:5 Changed 2 years ago by Ashish1206

Resolution: invalid
Status: closednew

comment:6 Changed 2 years ago by Ashish1206

Resolution: worksforme
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top