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)
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.
Related
I created an app two days ago, added some models, and migrated successfully. And since, I haven't added or changed anything but I added something today and tried to migrate, after making migrations and tried to migrate, I got this error:
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions, students, user_upload
Running migrations:
Applying user_upload.0002_users_upload_phone_number...Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\core\management\base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\core\management\base.py", line 371, in execute
output = self.handle(*args, **options)
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\core\management\base.py", line 85, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\core\management\commands\migrate.py", line 243, in handle
post_migrate_state = executor.migrate(
File "C:\Users\aser\AppData\Roaming\Python\Python38\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 "C:\Users\aser\AppData\Roaming\Python\Python38\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 "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\db\migrations\executor.py", line 227, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\db\migrations\migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\db\migrations\operations\fields.py", line 104, in database_forwards
schema_editor.add_field(
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\db\backends\sqlite3\schema.py", line 328, in add_field
self._remake_table(model, create_field=field)
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\db\backends\sqlite3\schema.py", line 189, in _remake_table
self.effective_default(create_field)
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\db\backends\base\schema.py", line 303, in effective_default
return field.get_db_prep_save(self._effective_default(field), self.connection)
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\db\models\fields\__init__.py", line 1512, in get_db_prep_save
return connection.ops.adapt_decimalfield_value(self.to_python(value), self.max_digits, self.decimal_places)
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\db\backends\base\operations.py", line 523, in adapt_decimalfield_value
return utils.format_number(value, max_digits, decimal_places)
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\db\backends\utils.py", line 235, in format_number
value = value.quantize(decimal.Decimal(1).scaleb(-decimal_places), context=context)
decimal.InvalidOperation: [<class 'decimal.InvalidOperation'>]
I've been looking but can't really find what's wrong
This is my model
from django.db import models
from django.forms import ModelForm
class Users_Upload(models.Model):
first_name = models.CharField(max_length=120)
last_name = models.CharField(max_length=120)
email = models.CharField(max_length=120)
phone_number = models.DecimalField(max_digits=14, decimal_places=4)
address = models.CharField(max_length=120, default="Bay Area, San Francisco, California, USA")
and my admin
from django.contrib import admin
from .models import Users_Upload
admin.site.register(Users_Upload)
I've already solved it. I had to clear out all my migrations and re-migrate again.
I'm trying to override the save method and I think I write exactly what the document said, but get the error
from django.db import models
class Post(models.Model):
name = models.CharField(max_length = 20)
lower_name = models.CharField(max_length = 20)
def save(self, *args, **kwargs):
if not self.lower_name:
self.lower_name = self.name.lower()
super().save(*args, **kwargs)
here is the traceback when I call python manage.py migrate
(project_site) λ python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions, works
Running migrations:
Applying works.0018_post_url_name...Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\core\management\commands\migrate.py", line 234, in handle
fake_initial=fake_initial,
File "D:\Code\Python\project_site\.venv\lib\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 "D:\Code\Python\project_site\.venv\lib\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 "D:\Code\Python\project_site\.venv\lib\site-packages\django\db\migrations\executor.py", line 245, in apply_migration
state = migration.apply(state, schema_editor)
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\db\migrations\migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\db\migrations\operations\fields.py", line 112, in database_forwards
field,
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\db\backends\sqlite3\schema.py", line 327, in add_field
self._remake_table(model, create_field=field)
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\db\backends\sqlite3\schema.py", line 188, in _remake_table
self.effective_default(create_field)
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\db\backends\base\schema.py", line 233, in effective_default
return field.get_db_prep_save(self._effective_default(field), self.connection)
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\db\backends\base\schema.py", line 212, in _effective_default
default = field.get_default()
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\db\models\fields\__init__.py", line 797, in get_default
return self._get_default()
TypeError: save() missing 1 required positional argument: 'self'
python version: 3.6.8 django version: 2.2.4
Ran my server today and realized I had 'two unapplied migrations'. I ran the command makemigrations and it detected no change, so naturally I then ran migrate.
I get this error code on my terminal:
Applying Campaigns.0016_campaignrecruit_date...Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py", l
ine 371, in execute_from_command_line
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py", l
ine 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py", line
288, in run_from_argv
self.execute(*args, **cmd_options)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py", line
335, in execute
output = self.handle(*args, **options)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/migrat
e.py", line 200, in handle
fake_initial=fake_initial,
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/migrations/executor.py", lin
e 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/migrations/executor.py", lin
e 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/migrations/executor.py", lin
e 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/migrations/migration.py", li
ne 122, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/migrations/operations/fields
.py", line 84, in database_forwards
field,
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/backends/sqlite3/schema.py",
line 306, in add_field
self._remake_table(model, create_field=field)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/backends/sqlite3/schema.py",
line 178, in _remake_table
self.effective_default(create_field)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/backends/base/schema.py", li
ne 240, in effective_default
default = field.get_db_prep_save(default, self.connection)
File "/Library/Frameworks/Python.framework/Versions/3.6/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 "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/models/fields/__init__.py",
line 1276, in get_db_prep_value
value = self.get_prep_value(value)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/models/fields/__init__.py",
line 1271, in get_prep_value
return self.to_python(value)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/models/fields/__init__.py",
line 1233, in to_python
parsed = parse_date(value)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/dateparse.py", line 74, i
n parse_date
match = date_re.match(value)
TypeError: expected string or bytes-like object
So to me, it looks like a date field in my model campaignrecruit is getting an input that it doesn't know how to handle. Which I would understand. But the thing is I don't have a datefield in my campaignrecruit model. The Time field is intentionally commented out right now.
Here's my models.py:
class campaignrecruit(models.Model):
campaign = models.ForeignKey(startcampaign, on_delete=models.CASCADE)
volunteer = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
join = models.BooleanField()
#Time = models.IntegerField()
def __str__(self):
return str(self.volunteer)
What else would throw this error? Any and all help is appreciated.
Since no one else answered, I will. As Aritra stated, I totally forgot about the migration files that are created whenever you run the migrate command. I had removed these model fields from my models and whenever I migrated again there was an error removing the files in my migrations file. After manually going in and removing the files, my error was fixed.
The database was just out of sync with what django had in its files.
I am trying to follow the getting started tutorial for django oauth toolkit from:
https://django-oauth-toolkit.readthedocs.io/en/latest/rest-framework/getting_started.html
When I run migrate, I get this error:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 1003, in _constraint_names
if type_ is not None and infodict['type'] != type_:
KeyError: 'type'
Any help would be appreciated.
Complete Stack trace
Operations to perform:
Apply all migrations: admin, auth, contenttypes, oauth2_provider, sessions
Running migrations:
Applying oauth2_provider.0004_auto_20160525_1623...Traceback (most recent call last):
File "/Users/lr/lrapp1/manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 204, in handle
fake_initial=fake_initial,
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/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 "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/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 "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/migrations/migration.py", line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/migrations/operations/fields.py", line 216, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 515, in alter_field
old_db_params, new_db_params, strict)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 572, in _alter_field
index_names = self._constraint_names(model, [old_field.column], index=True, type_=Index.suffix)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 1003, in _constraint_names
if type_ is not None and infodict['type'] != type_:
KeyError: 'type'
It seems this error was caused by oauth2_provider migration. You should be able to fix it by going into {your venv}/Lib/site-packages/oauth2_provider/migrations and delete all your migrations files (except init.py) and then run again migrate. Hope this will be helpful
So I am trying to integrate my legacy postgresql to django. I have successfully created my models following this:
https://docs.djangoproject.com/en/1.11/howto/legacy-databases/
However when I add something to my models and try to migrate I get the following error:
> Operations to perform:
Apply all migrations: admin, auth, contenttypes, pSQL, sessions
Running migrations:
Applying pSQL.0001_initial...Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.7/site-packages/django/core/management/commands/migrate.py", line 204, in handle
fake_initial=fake_initial,
File "/Library/Python/2.7/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 "/Library/Python/2.7/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 "/Library/Python/2.7/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/Library/Python/2.7/site-packages/django/db/migrations/migration.py", line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/Library/Python/2.7/site-packages/django/db/migrations/operations/models.py", line 96, in database_forwards
schema_editor.create_model(model)
File "/Library/Python/2.7/site-packages/django/db/backends/base/schema.py", line 246, in create_model
definition, extra_params = self.column_sql(model, field)
File "/Library/Python/2.7/site-packages/django/db/backends/base/schema.py", line 136, in column_sql
db_params = field.db_parameters(connection=self.connection)
File "/Library/Python/2.7/site-packages/django/db/models/fields/__init__.py", line 647, in db_parameters
type_string = self.db_type(connection)
TypeError: db_type() takes exactly 1 argument (2 given)
The initial migration file:
https://gist.github.com/eayantsquare/c0d7b31268b298490a0e77f566746f8d
Edit:
The problem is gone but i am not sure what fixed it. I basically deleted migrtions and tried from the start. On the way, it was fixed somehow. I am going to leave question unanswered so maybe someone will have a more compact answer.