1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] I restored my DB from a wrong backup file where the table I need didn't exist but I...

Discussão em 'Python' iniciado por Stack, Setembro 8, 2025.

  1. Stack

    Stack Membro Participativo

    I had a blog_user table in my DB, but accidentally restored a wrong backup.sql file so it disappeared. I don't have blog_user table in DB right now, but I have a migration creating user model.

    I tried to re-run the migrations so that they re-create the table.

    Like this:

    python manage.py migrate blog zero

    or

    python manage.py migrate blog zero --fake

    But get errors:

    I get the errors: Traceback (most recent call last): File "C:\Python_scripts\blog_and_shop\manage.py", line 22, in main() File "C:\Python_scripts\blog_and_shop\manage.py", line 18, in main execute_from_command_line(sys.argv) File "C:\Python_scripts\blog_and_shop.venv\lib\site-packages\django\core\management_init_.py", line 442, in execute_from_command_line utility.execute() File "C:\Python_scripts\blog_and_shop.venv\lib\site-packages\django\core\management_init_.py", line 436, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\Python_scripts\blog_and_shop.venv\lib\site-packages\django\core\management\base.py", line 413, in run_from_argv self.execute(*args, **cmd_options) File "C:\Python_scripts\blog_and_shop.venv\lib\site-packages\django\core\management\base.py", line 459, in execute output = self.handle(*args, **options) File "C:\Python_scripts\blog_and_shop.venv\lib\site-packages\django\core\management\base.py", line 107, in wrapper res = handle_func(*args, **kwargs) File "C:\Python_scripts\blog_and_shop.venv\lib\site-packages\django\core\management\commands\migrate.py", line 303, in handle pre_migrate_apps = pre_migrate_state.apps File "C:\Python_scripts\blog_and_shop.venv\lib\site-packages\django\utils\functional.py", line 47, in get res = instance.dict[self.name] = self.func(instance) File "C:\Python_scripts\blog_and_shop.venv\lib\site-packages\django\db\migrations\state.py", line 566, in apps return StateApps(self.real_apps, self.models) File "C:\Python_scripts\blog_and_shop.venv\lib\site-packages\django\db\migrations\state.py", line 637, in init raise ValueError("\n".join(error.msg for error in errors)) ValueError: The field admin.LogEntry.user was declared with a lazy reference to 'blog.user', but app 'blog' doesn't provide model 'user'. The field blog.Comment.author was declared with a lazy reference to 'blog.user', but app 'blog' doesn't provide model 'user'. The field blog.Post.author was declared with a lazy reference to 'blog.user', but app 'blog' doesn't provide model 'user'. The field blog.Post.read_later_users was declared with a lazy reference to 'blog.user', but app 'blog' doesn't provide model 'user'. The field blog.Post_read_later_users.user was declared with a lazy reference to 'blog.user', but app 'blog' doesn't provide model 'user'.

    I thought that the problem might be that the user model is defined somewhere in lowercase and in uppercase somewhere else, so there's a conflict, but no, it's the same, uppercase everywhere.

    I don't understand the problem and don't know how to fix it

    models.py of my blog app:

    class Post(models.Model):
    title = models.CharField(max_length=255)
    # body = models.TextField()
    body = RichTextUploadingField(blank=True, null=True)
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    slug = models.SlugField(max_length=1000, null=True, blank=True)
    tags = TaggableManager(blank=True)
    read_later_users = models.ManyToManyField(get_user_model(), related_name='read_later_posts')
    preview_image = models.ImageField(upload_to=get_file_path_preview_images, null=True, blank=True)
    class Meta:
    ordering = ["created"]

    def __str__(self):
    return self.title

    def get_absolute_url(self):
    return reverse("blog:post_detail", args=[self.id])





    class User(AbstractUser):
    pass


    P.S.: If it's needed to provide some other code, comment and I'll add it.

    Continue reading...

Compartilhe esta Página