1

I am trying to do a simple sign in application using Django and host it on AWS using Amazon Linux My model is

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)

I have tried timezone.now().time and datetime.datetime.now().time() and none of these work

When I try to run migrate on the server I get this error log

  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)
JRoss
  • 11
  • 3
  • This works for me: `date = models.DateField(blank=True, null=True, default=datetime.date.today)` – cookiedough May 25 '17 at 17:51
  • Still giving me the same error as before – JRoss May 25 '17 at 18:13
  • I think it is the use of the timezone.now() that is not properly done. Try replacing the default for your TimeField fields with: `datetime.datetime.now()` - you will need to import datetime – cookiedough May 25 '17 at 19:15
  • 1
    I have tried all variations of datetime and timezone. I even tried to not have any defaults and am still getting the error above. – JRoss May 25 '17 at 19:42
  • Lookingat this message, it's actually not an error, it's just a warning. The hint section says: `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 ` Maybe try `django.utils.timezone.now` – cookiedough May 25 '17 at 19:50
  • The error is at the bottom of the log – JRoss May 25 '17 at 19:55
  • Oh forgot about that! I can't really think of anything but take a look at this [link](https://stackoverflow.com/questions/24896613/missing-1-required-positional-argument), someone had a similar issue with a different function. Sounds like your issue is very minor. Good luck :) – cookiedough May 25 '17 at 20:20

1 Answers1

0

For me this seemed to be an issue with mySQL that I was using as my database. I solved this by moving to the default sqlLite file.

JRoss
  • 11
  • 3