Позже я добавил новое поле ForeignKey в модель. Но я столкнулся с такой ошибкой. Хотя я удаляю это поле, удаляю базу данных и снова выполняю миграцию, я получаю эту ошибку.
models.py / gayrimenkul
class Post(models.Model):
seller = models.ForeignKey('user.User',max_length=120,blank=False,null=False,verbose_name="İlan Sahibi",on_delete=models.CASCADE,default="admin")
title = models.CharField(max_length=120,blank=False,verbose_name="Başlık",help_text="Başlık Giriniz.")
slug = models.SlugField(max_length=122,default='',unique=True,null=False,verbose_name='Slug Alanı',editable=False)
price = models.FloatField(blank=False,verbose_name="Fiyat")
content = RichTextField(verbose_name="Detay")
img = models.ImageField(blank=True,verbose_name='Post Resim',default='',upload_to=upload_to)
created_date = models.DateTimeField(auto_now_add=True)
updated_date = models.DateTimeField(auto_now=True)
Связанная модель в поле ForeignKey - 'user. Пользователь ", потому что я создал свою собственную модель пользователя.
C:\Users\adilc\Desktop\Gayrimenkul\Gmn>python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, gayrimenkul, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying admin.0003_logentry_add_action_flag_choices... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0001_initial... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying auth.0009_alter_user_last_name_max_length... OK
Applying gayrimenkul.0001_initial... OK
Applying gayrimenkul.0002_post_seller...Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\adilc\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\adilc\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\adilc\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\base.py", line 316,
in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\adilc\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\base.py", line 353,
in execute
output = self.handle(*args, **options)
File "C:\Users\adilc\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\adilc\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\commands\migrate.py", line 203, in handle
fake_initial=fake_initial,
File "C:\Users\adilc\AppData\Local\Programs\Python\Python35-32\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\adilc\AppData\Local\Programs\Python\Python35-32\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\adilc\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\adilc\AppData\Local\Programs\Python\Python35-32\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\adilc\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\migrations\operations\fields.py", line 84, in database_forwards
field,
File "C:\Users\adilc\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\sqlite3\schema.py", line 300, in add_field
self._remake_table(model, create_field=field)
File "C:\Users\adilc\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\sqlite3\schema.py", line 172, in _remake_table
self.effective_default(create_field)
File "C:\Users\adilc\AppData\Local\Programs\Python\Python35-32\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\adilc\AppData\Local\Programs\Python\Python35-32\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\adilc\AppData\Local\Programs\Python\Python35-32\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\adilc\AppData\Local\Programs\Python\Python35-32\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\adilc\AppData\Local\Programs\Python\Python35-32\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: 'admin'
models.py / Пользователь
class User(AbstractBaseUser):
username = models.CharField(max_length = 30,
unique=True,
verbose_name = "Username",
validators = [RegexValidator(regex = USERNAME_REGEX,
message="Username must be alphanumeric or contain numbers",
code="invalid_username")])
email = models.EmailField(
max_length=255,
unique=True,
verbose_name = "Email",
)
registration_code = models.CharField(max_length=20,blank=False)
full_name = models.CharField(max_length=30, blank=True, null=True)
active = models.BooleanField(default = True)
staff = models.BooleanField(default = False)
admin = models.BooleanField(default = False)
timestamp = models.DateTimeField(auto_now_add=True)
objects = UserManager()
USERNAME_FIELD = "username"
REQUIRED_FIELDS = ["email"]
def __str__(self):
return self.username
def get_short_name(self):
pass
@property
def is_staff(self):
return self.staff
@property
def is_admin(self):
return self.admin
@property
def is_active(self):
return self.active
def has_perm(self, perm, obj=None):
return self.admin
def has_module_perms(self, app_label):
return self.admin