Samanta-Smith
@Samanta-Smith

Ошибка миграции при попытке хостинга сайта, что делать?

При попытке залить сайт на хостинг, сталкиваюсь с ошибкой при проведении миграции:
spoiler
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 "/var/www/u0932024/data/djangoenv/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/var/www/u0932024/data/djangoenv/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/var/www/u0932024/data/djangoenv/lib/python3.7/site-packages/django/core/management/base.py", line 328, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/var/www/u0932024/data/djangoenv/lib/python3.7/site-packages/django/core/management/base.py", line 369, in execute
    output = self.handle(*args, **options)
  File "/var/www/u0932024/data/djangoenv/lib/python3.7/site-packages/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/var/www/u0932024/data/djangoenv/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 233, in handle
    fake_initial=fake_initial,
  File "/var/www/u0932024/data/djangoenv/lib/python3.7/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 "/var/www/u0932024/data/djangoenv/lib/python3.7/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 "/var/www/u0932024/data/djangoenv/lib/python3.7/site-packages/django/db/migrations/executor.py", line 245, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/var/www/u0932024/data/djangoenv/lib/python3.7/site-packages/django/db/migrations/migration.py", line 124, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/var/www/u0932024/data/djangoenv/lib/python3.7/site-packages/django/db/migrations/operations/fields.py", line 112, in database_forwards
    field,
  File "/var/www/u0932024/data/djangoenv/lib/python3.7/site-packages/django/db/backends/mysql/schema.py", line 80, in add_field
    super().add_field(model, field)
  File "/var/www/u0932024/data/djangoenv/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 480, in add_field
    self.execute(sql, params)
  File "/var/www/u0932024/data/djangoenv/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 142, in execute
    cursor.execute(sql, params)
  File "/var/www/u0932024/data/djangoenv/lib/python3.7/site-packages/django/db/backends/utils.py", line 100, in execute
    return super().execute(sql, params)
  File "/var/www/u0932024/data/djangoenv/lib/python3.7/site-packages/django/db/backends/utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/var/www/u0932024/data/djangoenv/lib/python3.7/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/var/www/u0932024/data/djangoenv/lib/python3.7/site-packages/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
  File "/var/www/u0932024/data/djangoenv/lib/python3.7/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/var/www/u0932024/data/djangoenv/lib/python3.7/site-packages/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
  File "/var/www/u0932024/data/djangoenv/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 74, in execute
    return self.cursor.execute(query, args)
  File "/var/www/u0932024/data/djangoenv/lib/python3.7/site-packages/MySQLdb/cursors.py", line 209, in execute
    res = self._query(query)
  File "/var/www/u0932024/data/djangoenv/lib/python3.7/site-packages/MySQLdb/cursors.py", line 315, in _query
    db.query(q)
  File "/var/www/u0932024/data/djangoenv/lib/python3.7/site-packages/MySQLdb/connections.py", line 239, in query
    _mysql.connection.query(self, query)
django.db.utils.OperationalError: (1067, "Invalid default value for 'id'")

В службе поддержки мне сказали:
>В файле settings.py указали sql_mode. Сейчас миграция завершается ошибок из-за того, что скрипты миграции вашего приложения не рассчитаны на использование mysql5.7. Вам необходимо скорректировать скрипты миграции. Рекомендуем ознакомиться со следующим топиком(второй ответ) -
https://stackoverflow.com/questions/27548979/djang...


Вот модели
spoiler
class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE,related_name = 'profile')
    bio = models.IntegerField(default=0)

@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
    if created:
        Profile.objects.create(user=instance)

@receiver(post_save, sender=User)
def save_user_profile(sender, instance, **kwargs):
    instance.profile.save()
class Case(models.Model):
    name = models.CharField(max_length=20,default='qwerty',primary_key=True)
    price = models.IntegerField()
    describe =  models.TextField(default='qwerty')
    caseimg = models.ImageField(upload_to='images', default="",)
    img1 = models.ImageField(upload_to='images', default="",)
    nam1 = models.CharField(max_length=40,default='qwerty')
    img2 = models.ImageField(upload_to='images', default="",)
    nam2 = models.CharField(max_length=40,default='qwerty')
    img3 = models.ImageField(upload_to='images', default="",)
    nam3 = models.CharField(max_length=40,default='qwerty')
    img4 = models.ImageField(upload_to='images', default="",)
    nam4 = models.CharField(max_length=40,default='qwerty')
    img5 = models.ImageField(upload_to='images', default="",)
    nam5 = models.CharField(max_length=40,default='qwerty')
    img6 = models.ImageField(upload_to='images', default="",)
    nam6 = models.CharField(max_length=40,default='qwerty')
class Items(models.Model):
    name = models.CharField(max_length=20)
    owner = models.ForeignKey(Profile, on_delete = models.CASCADE)
    mydate = models.DateTimeField(default=datetime.now()+timedelta(days=90))
    def yearpublished(self):
        return self.mydate.strftime("%d/%m/%y")


В интернете есть информация по решению этой проблемы, но вникнуть в нее у меня не выходит. Заранее спасибо.
  • Вопрос задан
  • 153 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы