I have a problem with Djang makemigrations / migrate tool
- I have a Withdraw model with foreignkey to an Employee table. Everything is working fine
models.py
from django.contrib.auth.models import User
class Withdraw(models.Model):
employee_id = models.ForeignKey(Employee, on_delete = models.PROTECT)
amount = models.IntegerField(default=0)
withdraw_date = models.DateTimeField(default=timezone.now)
is_confirmed_by_employer = models.BooleanField(default=False)
I want to change it and have user as a foreignkey to user:
user = models.ForeignKey(User, on_delete=models.CASCADE)
I run makemigrations and I have this errormessage:
You are trying to add a non-nullable field 'user' to withdraw without a default; we can't do that (the database needs something to populate existing rows). Please select a fix: 1) Provide a one-off default now (will be set on all existing rows with a null value for this column) 2) Quit, and let me add a default in models.py
- If I press 1, then I have the following message, what I dont really get, why shall I put datetime or timezone.now to user??
Select an option: 1 Please enter the default value now, as valid Python The datetime and django.utils.timezone modules are available, so you can do e.g. timezone.now Type 'exit' to exit this prompt
- I tried to delete migrates folder and recreate migration files as was adviced in some other forum posts. When I recreate the migrations with createmigrations Withdraw command and migrate it to postgresSql the Withdraw table is not created however the tool is writing that the table is created and migrated.
So Either way, Im not able to migrate this small change to the DB. Do you have any opinions? Thx!