python Web框架 Django学习(2)

创建应用.

按照实例敲,但是失败了。。所以复制粘帖看看结果啥样,再对比下。研究哪错了。

正常结果输出:

root@smart:~/web_scan_django# python manage.py sql polls
BEGIN;
CREATE TABLE `polls_poll` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `question` varchar(200) NOT NULL,
    `pub_date` datetime NOT NULL
)
;
CREATE TABLE `polls_choice` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `poll_id` integer NOT NULL,
    `choice_text` varchar(200) NOT NULL,
    `votes` integer NOT NULL
)
;
ALTER TABLE `polls_choice` ADD CONSTRAINT `poll_id_refs_id_3aa09835` FOREIGN KEY (`poll_id`) REFERENCES `polls_poll` (`id`);

COMMIT;

model.py

from django.db import models

# Create your models here.
#class Poll(models.Model):
#  question = models.CharField(max_length=200)
#  pub_date = models.DateTimeField('date published')

#class Choice(models.Model):
#  poll = models.ForeignKey(Poll)
#  choice_test = models.CharField(max_length=200)
#  votes = models.IntegerField(defalut=0)

class Poll(models.Model):
    question = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')

class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice_text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)
原文地址:https://www.cnblogs.com/xiaoCon/p/3497235.html