Opened 15 months ago

Closed 7 months 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: kunitoki 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 15 months 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 15 months ago by aaugustin

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

comment:3 follow-up: Changed 15 months ago by andrewgodwin

  • Resolution set to invalid
  • Status changed from new to closed

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 7 months 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 7 months ago by Ashish1206 (previous) (diff)

comment:5 Changed 7 months ago by Ashish1206

  • Resolution invalid deleted
  • Status changed from closed to new

comment:6 Changed 7 months ago by Ashish1206

  • Resolution set to worksforme
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.
Back to Top