Reputation: 4371
my model.py file is
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)
for "class Book" I already created table in MySQL using manage.py syncdb
. But I am in the way to update the db with new table named as "Author" i need the procedure for doing the same. Because I am trying to do the latter in the same way but table is not created in the DB.
Upvotes: 1
Views: 121
Reputation: 752
`python syncdb` should not create any changes in the existing table
Use south migration concept.run the following command
python manage.py migrate
will make the changes in models.
Upvotes: 1
Reputation: 15320
syncdb
should create newly-specified tables; if Author
is not being created it is because it's not coded in a valid manner. Note that the line
age=int
results in a syntax error; you should specify an integer field this way:
age=models.IntegerField()
However you're better off having Django South taking care of anything you have related to DB migration.
Upvotes: 2