Thursday, 15 January 2015

python - The field does not have a default specified, yet is NOT NULL -


I do not know what Django is trying to say. I have a model, week two , which is received from Week , which comes from the model model I have another model , UserProfile . I want to use WeekTwo as a OneToOne key in UserProfile , so I inserted the following line of code:

  weekTwo = models .OneToOneField (Week Two)   

However, when I try to migrate my database using python manage.py schemamigration my_app --auto I get the following error:

  There is no default specified in the field 'UserProfile.weekTwo', yet it is not zero.   

I tried to declare default = 0 as my week two , but now I am getting this error when I go to schema migration I try to:

  IntegrityAir: Column succession two_ID is not unique   

In addition to this, the South is now saying that I have a The interim state between the migration and I might be able to recover I do not really know that its Or means.

Be aware before going forward, make sure that if the South has already migrated It has been unsuccessful, it is better to redo it, was working on the last migration .

You have two options, you can do first.

In other ways, you can week two field null and empty before

Then the south can generate migration by you

   Python manage.py schemamigration my_app --auto   < P> I'm sure the South will not complain about it now, then  
  Manage Python \ migrate   

If everything is okay now, You can now get back and week2 field

  weekTwo = models.OneToOne Fields can change ( noon)   

and generate migration then migrate .

However, when your field will be detected in the South NULL and does not have the default value, but the schemamigration From the step you would suggest providing a value for it, then here is the field OneToOneField , because the south gives you the chance to provide a default VA again to record its existence on the model weeks Specification of two fields will increase an error.

I think that if you do not work on the other side, then you have to go with data migrations , or give it a shot and for the second time this time it is Instead of creating null , blank , try changing the entire field type. Try it with;

  weekTwo = models.ForeignKey (WeekTwo)   

But keep in mind that data migration will definitely be smart and standard here The way.

No comments:

Post a Comment