【问题标题】:Issues Deploying Django Application to AWS because of Date model由于日期模型而将 Django 应用程序部署到 AWS 的问题
【发布时间】:2017-05-26 04:31:17
【问题描述】:

我正在尝试使用 Django 做一个简单的登录应用程序,并使用 Amazon Linux 在 AWS 上托管它 我的模型是

class Work(models.Model):
    user = models.CharField(_("User"),  max_length = 50, default = None)
    intern = models.ForeignKey("Intern", default = 1)
    date = models.DateField(_("Date"), default= timezone.now().today(), blank=True)
    time_in = models.TimeField(_("Time In"),default= timezone.now().time(), blank=True)
    time_out = models.TimeField(_("Time Out"),default= timezone.now().time(), blank=True)

我已经尝试过 timezone.now().time 和 datetime.datetime.now().time() 但这些都不起作用

当我尝试在服务器上运行迁移时,我得到了这个错误日志

  Apply all migrations: admin, auth, clockin, contenttypes, database, sessions, watson
  Running migrations:
  Applying clockin.0006_auto_20170523_1101...System check identified some issues:

  WARNINGS:
  clockin.Work.date: (fields.W161) Fixed default value provided.
  HINT: It seems you set a fixed date / time / datetime value as default for this field. This may not be what you want. If you want to have the current date as default, use `django.utils.timezone.now`
  Traceback (most recent call last):
  File "pmi_alpha/manage.py", line 22, in <module>
  execute_from_command_line(sys.argv)
  File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
  utility.execute()
  File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/core/management/__init__.py", line 359, in execute
  self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/core/management/base.py", line 294, in run_from_argv
  self.execute(*args, **cmd_options)
  File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/core/management/base.py", line 345, in execute
  output = self.handle(*args, **options)
  File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 204, in handle
  fake_initial=fake_initial,
  File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/db/migrations/executor.py", line 115, in migrate
  state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards
  state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
  state = migration.apply(state, schema_editor)
  File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/db/migrations/migration.py", line 129, in apply
  operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/db/migrations/operations/fields.py", line 204, in database_forwards
  schema_editor.alter_field(from_model, from_field, to_field)
  File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 495, in alter_field
  old_db_params, new_db_params, strict)
  File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 578, in _alter_field
  new_default = self.effective_default(new_field)
  File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 199, in effective_default
  default = field.get_default()
  File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/db/models/fields/__init__.py", line 769, in get_default
  return self.default()
  TypeError: localtime() missing 1 required positional argument: 'value'
   (ElasticBeanstalk::ExternalInvocationError)

【问题讨论】:

  • 这对我有用:date = models.DateField(blank=True, null=True, default=datetime.date.today)
  • 仍然给我和以前一样的错误
  • 我认为 timezone.now() 的使用没有正确完成。尝试将 TimeField 字段的默认值替换为:datetime.datetime.now() - 您需要导入日期时间
  • 我已经尝试了日期时间和时区的所有变体。我什至尝试不使用任何默认值,但仍然收到上述错误。
  • 看这条信息,其实不是错误,只是警告。提示部分说:HINT: It seems you set a fixed date / time / datetime value as default for this field. This may not be what you want. If you want to have the current date as default, use django.utils.timezone.now 也许试试django.utils.timezone.now

标签: python django amazon-web-services django-models


【解决方案1】:

对我来说,这似乎是我用作数据库的 mySQL 的问题。我通过移动到默认的 sqlLite 文件解决了这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-05
    • 2015-06-28
    • 2014-07-11
    • 2021-10-11
    • 1970-01-01
    • 2018-04-14
    • 1970-01-01
    相关资源
    最近更新 更多