here are the database tables I have made
from __future__ import unicode_literals
from django.db import models
class Venue(models.Model):
name = models.CharField(max_length=100)
address = models.ForeignKey('Address', blank=True, related_name='venue', on_delete=models.CASCADE)
phone = models.BigIntegerField(blank=True)
class Address(models.Model):
street1 = models.CharField(max_length=100)
street2 = models.CharField(max_length =100)
city = models.CharField(max_length = 100)
state = models.CharField(max_length = 2, blank =True)
zipcode = models.PositiveSmallIntegerField()
country = models.CharField(max_length = 100, blank = True)
and here is the stacktrace it seems to be django specifc. Anyone see this before?
Apply all migrations: admin, auth, contenttypes, sessions, venue
Running migrations:
Applying venue.0002_auto_20161220_2343...Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/rickus/211hospitality/com.suitsandtables/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/rickus/211hospitality/com.suitsandtables/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/rickus/211hospitality/com.suitsandtables/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/rickus/211hospitality/com.suitsandtables/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/home/rickus/211hospitality/com.suitsandtables/venv/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 204, in handle
fake_initial=fake_initial,
File "/home/rickus/211hospitality/com.suitsandtables/venv/local/lib/python2.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 "/home/rickus/211hospitality/com.suitsandtables/venv/local/lib/python2.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 "/home/rickus/211hospitality/com.suitsandtables/venv/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/rickus/211hospitality/com.suitsandtables/venv/local/lib/python2.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 "/home/rickus/211hospitality/com.suitsandtables/venv/local/lib/python2.7/site-packages/django/db/migrations/operations/fields.py", line 84, in database_forwards
field,
File "/home/rickus/211hospitality/com.suitsandtables/venv/local/lib/python2.7/site-packages/django/db/backends/postgresql/schema.py", line 21, in add_field
super(DatabaseSchemaEditor, self).add_field(model, field)
File "/home/rickus/211hospitality/com.suitsandtables/venv/local/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 395, in add_field
definition, params = self.column_sql(model, field, include_default=True)
File "/home/rickus/211hospitality/com.suitsandtables/venv/local/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 147, in column_sql
default_value = self.effective_default(field)
File "/home/rickus/211hospitality/com.suitsandtables/venv/local/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 221, in effective_default
default = field.get_db_prep_save(default, self.connection)
File "/home/rickus/211hospitality/com.suitsandtables/venv/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 909, in get_db_prep_save
return self.target_field.get_db_prep_save(value, connection=connection)
File "/home/rickus/211hospitality/com.suitsandtables/venv/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 755, in get_db_prep_save
prepared=False)
File "/home/rickus/211hospitality/com.suitsandtables/venv/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 938, in get_db_prep_value
value = self.get_prep_value(value)
File "/home/rickus/211hospitality/com.suitsandtables/venv/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 946, in get_prep_value
return int(value)
TypeError: int() argument must be a string or a number, not 'dict'
I am using a postgress backend. The looks of my code and migrate, it all makes no sense. Rather frustrating.
Related
models.py
This is the models.py file of my django project. I am getting this error in 5 line of the code below.I wanted to connect django default User model to my model by OneToOneField to provide multiple account functionality to my project. but I am stuck at this error that I don't understand.
plz, help.
from django.contrib.auth.models import User
# Create your models here.
class DailyTrack(models.Model):
user = models.OneToOneField(User, on_delete = models.CASCADE, related_name = 'Profile', default='')
income = models.IntegerField()
expense = models.IntegerField()
added = models.DateTimeField(auto_now_add=True)
def __str__(self):
return f'Income {self.amount} Income {self.amount}'
error is in the 4th line at the default field, I tried removing default or adding it but I am unable to understand this.
There is an error for
Operations to perform:
Apply all migrations: admin, auth, contenttypes, dailytrackapp, sessions
Running migrations:
Applying dailytrackapp.0003_dailytrack_user...Traceback (most recent call last):
File "C:\Users\NIitin\AppData\Roaming\Python\Python39\site-packages\django\db\models\fields\__init__.py", line 1774, in get_prep_value
return int(value)
ValueError: invalid literal for int() with base 10: 'null'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\NIitin\Desktop\MultiProj\DailyTrack\manage.py", line 22, in <module>
main()
File "C:\Users\NIitin\Desktop\MultiProj\DailyTrack\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\NIitin\AppData\Roaming\Python\Python39\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\NIitin\AppData\Roaming\Python\Python39\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\NIitin\AppData\Roaming\Python\Python39\site-packages\django\core\management\base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\NIitin\AppData\Roaming\Python\Python39\site-packages\django\core\management\base.py", line 371, in execute
output = self.handle(*args, **options)
File "C:\Users\NIitin\AppData\Roaming\Python\Python39\site-packages\django\core\management\base.py", line 85, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\NIitin\AppData\Roaming\Python\Python39\site-packages\django\core\management\commands\migrate.py", line 243, in handle
post_migrate_state = executor.migrate(
File "C:\Users\NIitin\AppData\Roaming\Python\Python39\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\NIitin\AppData\Roaming\Python\Python39\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\NIitin\AppData\Roaming\Python\Python39\site-packages\django\db\migrations\executor.py", line 227, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\NIitin\AppData\Roaming\Python\Python39\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\NIitin\AppData\Roaming\Python\Python39\site-packages\django\db\migrations\operations\fields.py", line 104, in database_forwards
schema_editor.add_field(
File "C:\Users\NIitin\AppData\Roaming\Python\Python39\site-packages\django\db\backends\sqlite3\schema.py", line 328, in add_field
self._remake_table(model, create_field=field)
File "C:\Users\NIitin\AppData\Roaming\Python\Python39\site-packages\django\db\backends\sqlite3\schema.py", line 189, in _remake_table
self.effective_default(create_field)
File "C:\Users\NIitin\AppData\Roaming\Python\Python39\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\NIitin\AppData\Roaming\Python\Python39\site-packages\django\db\models\fields\related.py", line 971, in get_db_prep_save
return self.target_field.get_db_prep_save(value, connection=connection)
File "C:\Users\NIitin\AppData\Roaming\Python\Python39\site-packages\django\db\models\fields\__init__.py", line 823, in get_db_prep_save
return self.get_db_prep_value(value, connection=connection, prepared=False)
File "C:\Users\NIitin\AppData\Roaming\Python\Python39\site-packages\django\db\models\fields\__init__.py", line 2388, in get_db_prep_value
value = self.get_prep_value(value)
File "C:\Users\NIitin\AppData\Roaming\Python\Python39\site-packages\django\db\models\fields\__init__.py", line 1776, in get_prep_value
raise e.__class__(
ValueError: Field 'id' expected a number but got 'null'.
NIitin#Nitin MINGW64 ~/Desktop/MultiProj/DailyTrack
$ python manage.py makemigrations
Migrations for 'dailytrackapp':
dailytrackapp\migrations\0001_initial.py
- Create model DailyTrack
NIitin#Nitin MINGW64 ~/Desktop/MultiProj/DailyTrack
$ python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, content types, dailytrackapp, sessions
Running migrations:
No migrations to apply.```
Can somebody help me? plz, I need to fix this urgently.
I'm trying to use django models to create constraints on my database, what am I doing wrong here?
I'm using django 2.2.2 on Python 3.7.3
Here is my model class:
class Client(models.Model):
class Meta:
db_table = 'Client'
constraints = [
models.CheckConstraint(check=models.Q(cnpj__regex='\\d{14}'), name='valid_cnpj'),
]
id = HashidAutoField(primary_key=True)
trade_name = models.CharField(max_length=200)
cnpj = models.CharField(max_length=14)
business_name = models.CharField(max_length=200, null=True)
Error message: AttributeError: 'str' object has no attribute 'connector'
Full traceback:
Running migrations:
Applying global_models.0008_auto_20190809_1747...Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\Celere.LAPTOP-FLPOSE6C\PycharmProjects\api_django\venv\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\Celere.LAPTOP-FLPOSE6C\PycharmProjects\api_django\venv\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Celere.LAPTOP-FLPOSE6C\PycharmProjects\api_django\venv\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Celere.LAPTOP-FLPOSE6C\PycharmProjects\api_django\venv\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "C:\Users\Celere.LAPTOP-FLPOSE6C\PycharmProjects\api_django\venv\lib\site-packages\django\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\Celere.LAPTOP-FLPOSE6C\PycharmProjects\api_django\venv\lib\site-packages\django\core\management\commands\migrate.py", line 234, in handle
fake_initial=fake_initial,
File "C:\Users\Celere.LAPTOP-FLPOSE6C\PycharmProjects\api_django\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 "C:\Users\Celere.LAPTOP-FLPOSE6C\PycharmProjects\api_django\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 "C:\Users\Celere.LAPTOP-FLPOSE6C\PycharmProjects\api_django\venv\lib\site-packages\django\db\migrations\executor.py", line 245, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\Celere.LAPTOP-FLPOSE6C\PycharmProjects\api_django\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 "C:\Users\Celere.LAPTOP-FLPOSE6C\PycharmProjects\api_django\venv\lib\site-packages\django\db\migrations\operations\models.py", line 827, in database_forwards
schema_editor.add_constraint(model, self.constraint)
File "C:\Users\Celere.LAPTOP-FLPOSE6C\PycharmProjects\api_django\venv\lib\site-packages\django\db\backends\base\schema.py", line 343, in add_constraint
sql = constraint.create_sql(model, self)
File "C:\Users\Celere.LAPTOP-FLPOSE6C\PycharmProjects\api_django\venv\lib\site-packages\django\db\models\constraints.py", line 47, in create_sql
check = self._get_check_sql(model, schema_editor)
File "C:\Users\Celere.LAPTOP-FLPOSE6C\PycharmProjects\api_django\venv\lib\site-packages\django\db\models\constraints.py", line 37, in _get_check_sql
where = query.build_where(self.check)
File "C:\Users\Celere.LAPTOP-FLPOSE6C\PycharmProjects\api_django\venv\lib\site-packages\django\db\models\sql\query.py", line 1296, in build_where
return self._add_q(q_object, used_aliases=set(), allow_joins=False, simple_col=True)[0]
File "C:\Users\Celere.LAPTOP-FLPOSE6C\PycharmProjects\api_django\venv\lib\site-packages\django\db\models\sql\query.py", line 1302, in _add_q
connector = q_object.connector
I have 2 classes. Student and parent. The parent class links to the student class via a models.ForeignKey(Student, on_delete=models.CASCADE)
When running makemigrations django asked whether I wanted to input because there was no default. So I input "defult". Turns out it wanted a string and now whenever I run migrate it gives me the ValueError which I have no clue how to fix or what to do. I've tried deleting migrations folder and removing both models but still nope.
C:\Users\Egor\Desktop\mysite>python manage.py makemigrations
Migrations for 'main':
main\migrations\0028_auto_20190129_2010.py
- Alter field student_joined on student
C:\Users\Egor\Desktop\mysite>python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, main, sessions
Running migrations:
Applying main.0007_auto_20190129_1732...Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-
packages\django\core\management\__init__.py", line 381, in
execute_from_command_line
utility.execute()
File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\base.py", line 353, in execute
output = self.handle(*args, **options)
File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\commands\migrate.py", line 203, in handle
fake_initial=fake_initial,
File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\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 "C:\Users\Egor\AppData\Local\Programs\Python\Python37\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 "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\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 "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\migrations\operations\fields.py", line 84, in database_forwards
field,
File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\sqlite3\schema.py", line 309, in add_field
self._remake_table(model, create_field=field)
File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\sqlite3\schema.py", line 181, in _remake_table
self.effective_default(create_field)
File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\base\schema.py", line 239, in effective_default
return field.get_db_prep_save(default, self.connection)
File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\fields\related.py", line 937, in get_db_prep_save
return self.target_field.get_db_prep_save(value, connection=connection)
File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\fields\__init__.py", line 790, in get_db_prep_save
return self.get_db_prep_value(value, connection=connection, prepared=False)
File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\fields\__init__.py", line 956, in get_db_prep_value
value = self.get_prep_value(value)
File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\fields\__init__.py", line 965, in get_prep_value
return int(value)
ValueError: invalid literal for int() with base 10: 'Defult'
models code:
class Student(models.Model):
student_name = models.CharField(max_length=200)
student_gender = models.CharField(max_length=1)
student_parent_email = models.EmailField()
student_joined = models.DateTimeField('date joined', default=datetime.now())
def __str__(self):
return self.student_name
class Parent(models.Model):
mother = models.CharField(max_length=200)
father = models.CharField(max_length=200)
stu = models.ForeignKey(Student, on_delete=models.CASCADE)
I have no clue what to do now. Please help as to how to get rid of this value error.
Thank you
I have a problem when I write in cmd this "python manage.py migrate"
I found this error
{ValueError: invalid literal for int() with base 10: 'SOME STRING'}
this is my code
class GameScore(models.Model):
FirstTeam = models.CharField(max_length=256, null=True)
SecondTeam = models.CharField(max_length=256, null=True)
first_team_score = models.IntegerField(default=0)
second_team_score = models.IntegerField(default=0)
game_date = models.DateTimeField(auto_now=True)
def __str__(self):
return '{} {} - {} {}'.format(self.FirstTeam, self.first_team_score, self.SecondTeam, self.second_team_score)
this is full Traceback
https://i.stack.imgur.com/RM284.png
Apply all migrations: admin, auth, contenttypes, sessions, team
Running migrations:
Applying team.0007_auto_20180504_0343...Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\haytham\Desktop\teammanager_env\lib\site-packages\django\core\management\__init__.py", line 364, in execute_from_command_line
utility.execute()
File "C:\Users\haytham\Desktop\teammanager_env\lib\site-packages\django\core\management\__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\haytham\Desktop\teammanager_env\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\haytham\Desktop\teammanager_env\lib\site-packages\django\core\management\base.py", line 330, in execute
output = self.handle(*args, **options)
File "C:\Users\haytham\Desktop\teammanager_env\lib\site-packages\django\core\management\commands\migrate.py", line 204, in handle
fake_initial=fake_initial,
File "C:\Users\haytham\Desktop\teammanager_env\lib\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 "C:\Users\haytham\Desktop\teammanager_env\lib\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 "C:\Users\haytham\Desktop\teammanager_env\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\haytham\Desktop\teammanager_env\lib\site-packages\django\db\migrations\migration.py", line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\Users\haytham\Desktop\teammanager_env\lib\site-packages\django\db\migrations\operations\fields.py", line 88, in database_forwards
field,
File "C:\Users\haytham\Desktop\teammanager_env\lib\site-packages\django\db\backends\sqlite3\schema.py", line 238, in add_field
self._remake_table(model, create_field=field)
File "C:\Users\haytham\Desktop\teammanager_env\lib\site-packages\django\db\backends\sqlite3\schema.py", line 113, in _remake_table
self.effective_default(create_field)
File "C:\Users\haytham\Desktop\teammanager_env\lib\site-packages\django\db\backends\base\schema.py", line 229, in effective_default
default = field.get_db_prep_save(default, self.connection)
File "C:\Users\haytham\Desktop\teammanager_env\lib\site-packages\django\db\models\fields\related.py", line 963, in get_db_prep_save
return self.target_field.get_db_prep_save(value, connection=connection)
File "C:\Users\haytham\Desktop\teammanager_env\lib\site-packages\django\db\models\fields\__init__.py", line 770, in get_db_prep_save
prepared=False)
File "C:\Users\haytham\Desktop\teammanager_env\lib\site-packages\django\db\models\fields\__init__.py", line 958, in get_db_prep_value
value = self.get_prep_value(value)
File "C:\Users\haytham\Desktop\teammanager_env\lib\site-packages\django\db\models\fields\__init__.py", line 966, in get_prep_value
return int(value)
ValueError: invalid literal for int() with base 10: 'SOME STRING'
I don't know how to solve this problem
Think of the () as a list. You need numbers to tell which value to pull.
return '{0} {1} - {2} {3}'.format(self.FirstTeam, self.first_team_score, self.SecondTeam, self.second_team_score)
If you are using Python 3.6 you could use f’{self.whatever}’.
there is no issue when applied makmigration on "model" but migration command throwing exception "error" ValueError: invalid literal for int() with base 10: 'null'.
I got this error when i make change on "emails_for_help" help field
I tried by fake_migration and migrated but no use
model
class Setup_user(models.Model):
organization=models.CharField(max_length=200,blank=False,default="")
email_id=models.EmailField(unique=True)
CEO = 'CEO'
GENERAL_MANAGER = 'GM'
JCHOICES = (
(CEO, 'CEO'),
(GENERAL_MANAGER, 'General Manager'),
)
Designation = models.CharField(max_length=5,choices=JCHOICES)
LEVEL1 = "L1"
LEVEL2 = "L2"
LCHOICES = (
(LEVEL1,"Level 1"),
(LEVEL2,"Level 2"),
)
job_level=models.CharField(max_length=2,choices=LCHOICES)
EMAIL_CHOICES = ((str(q.email), str(q.email)) for q in User.objects.all())
emails_for_help = MultiSelectField(choices=EMAIL_CHOICES,default="null",max_length=5000,help_text="select with whom you want to share knowledge")
def __str__(self):
return self.email_id
error:
C:\Users\Ekatech7\PycharmProjects\baseproject>python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, pkm_app, sessions
Running migrations:
Applying pkm_app.0015_auto_20180417_1723...Traceback (most recent call
last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Ekatech7\PycharmProjects\baseproject\venv\lib\site-
packages\django\core\management\__init__.py", line 371, in
execute_from_command_line
utility.execute()
File "C:\Users\Ekatech7\PycharmProjects\baseproject\venv\lib\site-
packages\django\core\management\__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Ekatech7\PycharmProjects\baseproject\venv\lib\site-
packages\django\core\management\base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Ekatech7\PycharmProjects\baseproject\venv\lib\site-
packages\django\core\management\base.py", line 335, in execute
output = self.handle(*args, **options)
File "C:\Users\Ekatech7\PycharmProjects\baseproject\venv\lib\site-
packages\django\core\management\commands\migrate.py", line 200, in handle
fake_initial=fake_initial,
File "C:\Users\Ekatech7\PycharmProjects\baseproject\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 "C:\Users\Ekatech7\PycharmProjects\baseproject\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 "C:\Users\Ekatech7\PycharmProjects\baseproject\venv\lib\site-
packages\django\db\migrations\executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\Ekatech7\PycharmProjects\baseproject\venv\lib\site-
packages\django\db\migrations\migration.py", line 122, in apply
operation.database_forwards(self.app_label, schema_editor, old_state,
project_state)
File "C:\Users\Ekatech7\PycharmProjects\baseproject\venv\lib\site-
packages\django\db\migrations\operations\fields.py", line 84, in
database_forwards
field,
File "C:\Users\Ekatech7\PycharmProjects\baseproject\venv\lib\site-
packages\django\db\backends\sqlite3\schema.py", line 306, in add_field
self._remake_table(model, create_field=field)
File "C:\Users\Ekatech7\PycharmProjects\baseproject\venv\lib\site -
packages\django\db\backends\sqlite3\schema.py", line 178, in _remake_table
self.effective_default(create_field)
File "C:\Users\Ekatech7\PycharmProjects\baseproject\venv\lib\site-
packages\django\db\backends\base\schema.py", line 224, in effective_default
default = field.get_db_prep_save(default, self.connection)
File "C:\Users\Ekatech7\PycharmProjects\baseproject\venv\lib\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 "C:\Users\Ekatech7\PycharmProjects\baseproject\venv\lib\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 "C:\Users\Ekatech7\PycharmProjects\baseproject\venv\lib\site-
packages\django\db\models\fields__init__.py", line 939, in
get_db_prep_value
value = self.get_prep_value(value)
File "C:\Users\Ekatech7\PycharmProjects\baseproject\venv\lib\site-
packages\django\db\models\fields__init__.py", line 947, in get_prep_value
return int(value)
ValueError: invalid literal for int() with base 10: 'null'
Your CHOICES don’t have ”null” as an option. If you want null values to be stored, you have to set null=True, which means that when amodelField is blank=True, the empty value will be stored as null. If you just want your form to not pick an option when it loads, don’t set default. The error is looking for this:
EMAIL_CHOICES = (
(“null”, “null”)
(str(q.email), str(q.email)
)
I think you also have your for loop backwards. I believe it should be:
for q in User.objects.all():
(str(q.email), str(q.email)
issue resolved.
approach i chosen for choices in above model was blunder mistake.
It is resolved by using many to many relation for "emails for help" column and modelform with query set approch.
class Set_User_Form(ModelForm):
emails_for_help= forms.ModelMultipleChoiceField(queryset=User.objects.all(),widget=forms.CheckboxSelectMultiple)
class Meta:
model=Setupuser
exclude=["email_id"]