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):
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:
PowerShell Result:
Apply all migrations: blog
Running migrations:
No migrations to apply.
When i try to fake migrations it also is not working:
PowerShell Result:
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:\Users\Administrator PC\Desktop\mysite\blog\templates\blog\base.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.
解决方案
像这样在迁移命令中使用您的应用名称
python manage.py makemigrations blog
python manage.py migrate blog
推荐阅读
- c++ - 如何在没有高 CPU 使用率的情况下检测 Windows 中的按键?
- python - ValueError: 操作数不能与形状 (100,) (99,) 一起在 Python 中广播错误
- javascript - 如何在每组之间延迟发出特定缓冲区大小的值
- r - 为什么这个闪亮的应用程序可以在 ShinyApps.io 上运行,但不能在 Shiny Server 上运行?
- r - 我如何使用数据框中的值在 ggplot 2 中绘制图形并将它们转换为四舍五入的百分比标签
- java - document.getMetadata().hasPendingWrites() 显示为真,因为数据未存储在 Firebase 中
- javascript - 将嵌套数组转换为普通数组
- mysql - XAMPP MySQL 意外关闭
- postgresql - 无法使用 pgAdmin 访问 RDS 上的 Db 实例
- javascript - 延迟加载不适用于图像滑块插件(WordPress、PHP、JavaScript)