简体   繁体   English

Django 不迁移应用程序

[英]Django does not migrate app

I'm working on a django project for learning purpose.我正在从事一个 django 项目以供学习。 I've created an app organization and installed it.我创建了一个应用organization并安装了它。 When I run python manage.py makemigrations organization it works fine shows the changes.当我运行python manage.py makemigrations organization它工作正常显示了更改。

Migrations for 'organization':
  organization/migrations/0001_initial.py:
    - Create model Organization
    - Create model Principle

But when I run python manage.py migrate organization it doesn't migrate and shows no changes to apply.但是,当我运行python manage.py migrate organization它不会迁移,也不会显示任何要应用的更改。

Operations to perform:
  Apply all migrations: organization
Running migrations:
  No migrations to apply.

I'm using postgresql and tried drop owned by user_name;我正在使用postgresql并尝试使用drop owned by user_name; after deleting all migrations folders.删除所有migrations文件夹后。 But still doesn't work.但仍然不起作用。 It shows every time the same thing.它每次都显示同样的事情。 How to resolve this ?如何解决这个问题?

Environment:环境:
OS version Ubuntu 16.04操作系统版本 Ubuntu 16.04
Django version 1.10.3 Django 版本 1.10.3
PostgreSQL version 9.5.7 PostgreSQL 版本 9.5.7

organization/models.py组织/模型.py

from django.db import models
from django.contrib.postgres.fields import JSONField    

class Principle(models.Model):
    name = models.CharField(max_length=256)
    description = models.CharField(max_length=256)
    contact_no = models.CharField(max_length=256)
    status = models.BooleanField()


class Organization(models.Model):
    name = models.CharField(max_length=256)
    liceneses = [
        ('pvt','Private Limited',),
        ('pub','Public Limited',),
        ('part','Partnership',),
        ('prop','proprietary',)
    ]

    licenese_type = models.CharField(max_length=10, choices=liceneses)
    key_person_name = models.CharField(max_length=256)
    key_person_position = models.CharField(max_length=256)
    key_person_contact_no = models.CharField(max_length=45)
    primary_organization_contact = models.CharField(max_length=45)
    organization_address = models.TextField()
    additional_info = JSONField()
    date_of_registration = models.CharField(max_length=45)
    status = models.BooleanField()

in these case delete all the migrations files from migration folder except __init__.py file for all apps, make sure you have the apps in the installed apps在这些情况下,从迁移文件夹中删除所有迁移文件,除了所有应用程序的__init__.py文件,确保您在已安装的应用程序中有这些应用程序

then delete the database tables然后删除数据库表

NOTE: Be careful to backup important FILES when you delete your DATABASE !注意:删除数据库时请注意备份重要文件!

run python manage.py migrate
run python manage.py makemigrations
run python manage.py migrate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM