I am using ldap to do authentication, just like Understanding Django-LDAP authentication.
My model is:
class MyFile(models.Model):
file = models.FileField(upload_to="files")
slug = models.SlugField(max_length=50, blank=True)
user = models.ForeignKey(User, unique=True)
But I cannot make migrations:
python src/manage.py makemigrations
You are trying to add a non-nullable field 'user' to myfile 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)
2) Quit, and let me add a default in models.py
Select an option:
Then I input datetime.date.today() and run python manage.py migrate The error is:
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 915, in get_prep_value
return int(value)
TypeError: int() argument must be a string or a number, not 'datetime.date'
Any idea? Thanks
UPDATE
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='MyFile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('file', models.FileField(upload_to='files')),
('slug', models.SlugField(blank=True)),
('user', models.ForeignKey(User, blank=True, null=True)),
],
),
]
Error:
ValueError: Lookup failed for model referenced by field fileupload.MyFile.user: auth.User