我正在学习Udemy课程,我在运行
时遇到了这个错误python manage.py migrate
错误是:
TypeError: int() argument must be a string, a bytes-like object or a number, not 'datetime.datetime'
这是我的代码:
from django.conf import settings
from django.db import models
# Create your models here.
class Tweet(models.Model):
# user
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
content = models.CharField(max_length=140)
updated = models.DateTimeField(auto_now=True)
timestamp = models.DateTimeField(auto_now_add=True)
def __str__(self):
return str(self.content)
我的追溯:
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/Users/isaac/Dev/tweetme/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/Users/isaac/Dev/tweetme/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/isaac/Dev/tweetme/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/isaac/Dev/tweetme/lib/python3.6/site-packages/django/core/management/base.py", line 335, in execute
output = self.handle(*args, **options)
File "/Users/isaac/Dev/tweetme/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 200, in handle
fake_initial=fake_initial,
File "/Users/isaac/Dev/tweetme/lib/python3.6/site-packages/django/db/migrations/executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/Users/isaac/Dev/tweetme/lib/python3.6/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/Users/isaac/Dev/tweetme/lib/python3.6/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/Users/isaac/Dev/tweetme/lib/python3.6/site-packages/django/db/migrations/migration.py", line 122, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/Users/isaac/Dev/tweetme/lib/python3.6/site-packages/django/db/migrations/operations/fields.py", line 84, in database_forwards
field,
File "/Users/isaac/Dev/tweetme/lib/python3.6/site-packages/django/db/backends/sqlite3/schema.py", line 306, in add_field
self._remake_table(model, create_field=field)
File "/Users/isaac/Dev/tweetme/lib/python3.6/site-packages/django/db/backends/sqlite3/schema.py", line 178, in _remake_table
self.effective_default(create_field)
File "/Users/isaac/Dev/tweetme/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 240, in effective_default
default = field.get_db_prep_save(default, self.connection)
File "/Users/isaac/Dev/tweetme/lib/python3.6/site-packages/django/db/models/fields/related.py", line 936, in get_db_prep_save
return self.target_field.get_db_prep_save(value, connection=connection)
File "/Users/isaac/Dev/tweetme/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 767, in get_db_prep_save
return self.get_db_prep_value(value, connection=connection, prepared=False)
File "/Users/isaac/Dev/tweetme/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 939, in get_db_prep_value
value = self.get_prep_value(value)
File "/Users/isaac/Dev/tweetme/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 947, in get_prep_value
return int(value)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'datetime.datetime'
我添加users
后立即创建了此错误。
提前致谢!