Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
464 views
in Technique[技术] by (71.8m points)

python - 如何解决python的迁移问题?(How to resolve the migration problem python?)

I have a problem with migration in this model.

(我在此模型中有迁移问题。)

So this is my initial class Post, it works perfectly(migration worked):

(这是我的第一堂课Post,它可以很好地工作(迁移有效):)

Initial Class Post

(头等舱职位)

class Post(models.Model):
    title = models.CharField(max_length=100)
    content = models.TextField()
    date_posted = models.DateTimeField(default=timezone.now)
    author = models.ForeignKey(User, on_delete=models.CASCADE) 

    def __str__(self):
        return self.title

I want to add a new column:

(我想添加一个新列:)

photos = models.ImageField(upload_to="/images/", default = None)

I deleted all migrations and so when i used makemigrations it works, but when i try to migrate i get nothing:

(我删除了所有迁移,因此当我使用makemigrations时,它可以工作,但是当我尝试迁移时,我什么也没得到:)

PowerShell Result:

(PowerShell结果:)

Apply all migrations: blog
Running migrations:
No migrations to apply.

When i try to fake migrations it also is not working:

(当我尝试伪造迁移时,它也不起作用:)

PowerShell Result:

(PowerShell结果:)

Target specific migration: 0001_initial, from blog
Running migrations:
  No migrations to apply.

After i run the server i get this error:

(运行服务器后,出现此错误:)

Trying to acces my local website:

(尝试访问我的本地网站:)

Error during template rendering
In template C:UsersAdministrator PCDesktopmysitelogemplateslogase.html, error at line 6

no such column: blog_post.photos
    {% load static %}
    <!DOCTYPE html>
    <html>
    <head>

        <!-- Required meta tags -->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

        <!-- Bootstrap CSS -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

        <link rel="stylesheet" type="text/css" href="{% static 'blog/main.css' %}">

        {% if title %}
            <title>Django Blog - {{ title }}</title>

Please help i don't know what to try more.

(请帮助我不知道该如何尝试。)

Thank you in advance.

(先感谢您。)

  ask by Nick Druta translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use your app name in migration command like this

(像这样在迁移命令中使用您的应用名称)

python manage.py makemigrations blog
python manage.py migrate blog

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...