如何在django中进行迁移

问题描述 投票:1回答:2

我的model.py文件是

from django.db import models

class Book(models.Model):
    book_id=models.AutoField(primary_key=True,unique=True)
    book_name=models.CharField(max_length=30)
    author_name=models.CharField(max_length=30)
    publisher_name=models.CharField(max_length=40)
    def __unicode__(self):
        return "%d %s %s %s" % (self.book_id,self.book_name, self.author_name,self.publisher_name)


class Author(models.Model):
    author_id=models.AutoField(primary_key=True)
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=40)
    email = models.EmailField()
    book=models.ForeignKey(Book)

    def __unicode__(self):
        return u'%d %s %s' % (self.author_id,self.first_name, self.last_name)

对于 "类书",我已经在MySQL中创建了表,利用 manage.py syncdb. 但我在更新数据库的方式与新的表命名为 "作者 "我需要做同样的过程。因为我试图以同样的方式做后者,但表没有在DB中创建。

django django-models database-migration
2个回答
1
投票
`python syncdb` should not create any changes in the existing table

使用南移概念,运行以下命令

python manage.py migrate

将在模型中进行更改。


2
投票

syncdb 应创建新指定的表;如果 Author 没有被创建,这是因为它没有以有效的方式编码。请注意,这一行

age=int

导致语法错误;你应该指定一个 整数字段 这样。

age=models.IntegerField()

不过,你最好有 Django South 处理任何与DB迁移有关的问题。

© www.soinside.com 2019 - 2024. All rights reserved.