python django 重新建模

node2:/app/mysite/blog#cat models.py
from django.db import models
from django.contrib import admin

# Create your models here.
class BlogPost(models.Model):
    title = models.CharField(max_length = 150)
    body = models.TextField()
    timestamp = models.DateTimeField()
    class Meta:
      ordering =('-timestamp',)
class BlogPostAdmin(admin.ModelAdmin):
    list_display = ('title','timestamp')
admin.site.register(BlogPost,BlogPostAdmin)
class Book(models.Model):
    title=models.CharField(max_length=100)
    author=models.URLField(max_length=200)
    length=models.IntegerField()


添加了
class Book(models.Model):
    title=models.CharField(max_length=100)
    author=models.URLField(max_length=200)
    length=models.IntegerField()



python 重新建模:

node2:/app/mysite#python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, blog, contenttypes, sessions
Running migrations:
  No migrations to apply.
  Your models have changes that are not yet reflected in a migration, and so won't be applied.
  Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
node2:/app/mysite#python manage.py migrate blog
Operations to perform:
  Apply all migrations: blog
Running migrations:
  No migrations to apply.
  Your models have changes that are not yet reflected in a migration, and so won't be applied.
  Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.



node2:/app/mysite#python manage.py makemigrations
Migrations for 'blog':
  blog/migrations/0002_auto_20171001_1904.py
    - Create model Book
    - Change Meta options on blogpost
node2:/app/mysite#python manage.py migrate blog
Operations to perform:
  Apply all migrations: blog
Running migrations:
  Applying blog.0002_auto_20171001_1904... OK
node2:/app/mysite#

mysql> select * from blog_book;
Empty set (0.00 sec)

mysql> select * from blog_blogpost;
+----+-----------+--------------+----------------------------+
| id | title     | body         | timestamp                  |
+----+-----------+--------------+----------------------------+
|  1 | 测试      | 1111         | 2017-09-26 02:24:54.000000 |
|  2 | aabbcc    | 112233aabbcc | 2017-09-26 02:27:23.000000 |
|  3 | ttt       | tttttttttt   | 2017-09-26 02:30:01.000000 |
|  4 | 9999      | 999999999    | 2017-09-27 00:17:56.000000 |
|  5 | xxx       | 达到达到     | 2017-09-28 02:21:21.000000 |
|  6 | www       | 呃呃呃       | 2017-09-29 06:58:08.000000 |
+----+-----------+--------------+----------------------------+
6 rows in set (0.00 sec)

原文地址:https://www.cnblogs.com/hzcya1995/p/13349513.html