我执行Python manage.py makemigrations和迁移时未检测到更改 [英] No changes detected when i excute Python manage.py makemigrations and migrate

查看:1081
本文介绍了我执行Python manage.py makemigrations和迁移时未检测到更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 python manage.py迁移十分之一进行迁移,但未检测到任何东西。我什至将数据库更改为postgres,但没有任何改变。甚至 python manage.py migration 都不起作用。可能是什么问题?

I tried to make migration using python manage.py migrations tithe but nothing is detected. I have even changed my database to postgres, but nothing has changed. Even python manage.py migrate is not working. What could be the problem?

@localhost church]$ python manage.py migrate tithe
Operations to perform:
  Apply all migrations: (none)
Running migrations:
  No migrations to apply.

这是我的模型。py代码

this is my model.py code

from __future__ import unicode_literals
from django.utils import timezone
from django.contrib.auth.models import User
from django.conf import settings
from django.contrib.auth import get_user_model
from django.core.signals import setting_changed
from django.dispatch import receiver
from django.db import models

# Create your models here.
class tithe(models.Model):
    member_code = models.ForeignKey(settings.AUTH_USER_MODEL)
    member = models.CharField(max_length=45)
    receipt_code = models.CharField(max_length=45, unique=True)
    tithes = models.IntegerField()
    combinedoffering = models.IntegerField()
    campmeetingoffering = models.IntegerField()
    churchbuilding = models.IntegerField()
    conference = models.IntegerField()
    localchurch = models.IntegerField()
    funds = models.IntegerField()
    total = models.IntegerField()
    created_date = models.DateTimeField(
            default=timezone.now)
    published_date = models.DateTimeField(
            blank=True, null=True)

    def publish(self):
        self.published_date = timezone.now()
        self.save()

    def __str__(self):
        return self.receitcode

    class Meta:
        abstract = True


推荐答案

该程序通过删除类meta中的 abstract = True 来工作。当我运行 python manage.py makemigrations什一税 python manage.py迁移什一税时将其删除后,效果很好

the program works by removing abstract = Truein the class meta.after removing it when i run python manage.py makemigrations tithe and python manage.py migrate tithe it works wells

from __future__ import unicode_literals
from django.utils import timezone
from django.contrib.auth.models import User
from django.conf import settings
from django.contrib.auth import get_user_model
from django.core.signals import setting_changed
from django.dispatch import receiver
from django.db import models

# Create your models here.
class tithe(models.Model):
    member_code = models.ForeignKey(settings.AUTH_USER_MODEL)
    member = models.CharField(max_length=45)
    receipt_code = models.CharField(max_length=45, unique=True)
    tithes = models.IntegerField()
    combinedoffering = models.IntegerField()
    campmeetingoffering = models.IntegerField()
    churchbuilding = models.IntegerField()
    conference = models.IntegerField()
    localchurch = models.IntegerField()
    funds = models.IntegerField()
    total = models.IntegerField()
    created_date = models.DateTimeField(
            default=timezone.now)
    published_date = models.DateTimeField(
            blank=True, null=True)

    def publish(self):
        self.published_date = timezone.now()
        self.save()

    def __str__(self):
        return self.receitcode

    class Meta:
        unique_together = ["receipt_code"]

这篇关于我执行Python manage.py makemigrations和迁移时未检测到更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆