我刚刚将我的开发环境从Ubuntu Linux迁移到Mac OSX雪豹。所有这些都在Linux上运行。在这两个方面,我已经将MySQL用于Django的db。
Django的重置功能不是为我的所有应用程序模型发出drop命令。这是我的models.py(为简洁起见删除了Forum和User对象字段):
from django.db import models
class Forum(models.Model):
...
class User(models.Model):
...
class Message(models.Model):
date = models.DateTimeField()
content_file = models.CharField(max_length=48)
summary_file = models.CharField(max_length=48)
user = models.ForeignKey(User)
thread = models.ForeignKey('self', blank=True, null=True)
lft = models.IntegerField(default=1)
rgt = models.IntegerField(default=2)
def __unicode__(self):
return str(self.date) + '_' + unicode(self.user)
class Message_forum(models.Model):
message = models.ForeignKey(Message)
forum = models.ForeignKey(Forum)
status = models.IntegerField()
position = models.IntegerField(blank=True, null=True)
def __unicode__(self):
return unicode(self.message) + '_' + unicode(self.forum)
这是django的sql命令的输出:
BEGIN;
CREATE TABLE `AO_forum` (
...
)
;
CREATE TABLE `AO_user` (
...
)
;
CREATE TABLE `AO_message` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`date` datetime NOT NULL,
`content_file` varchar(48) NOT NULL,
`summary_file` varchar(48) NOT NULL,
`user_id` integer NOT NULL,
`thread_id` integer,
`lft` integer NOT NULL,
`rgt` integer NOT NULL
)
;
ALTER TABLE `AO_message` ADD CONSTRAINT `user_id_refs_id_12d253fe` FOREIGN KEY (`user_id`) REFERENCES `AO_user` (`id`);
ALTER TABLE `AO_message` ADD CONSTRAINT `thread_id_refs_id_12262c89` FOREIGN KEY (`thread_id`) REFERENCES `AO_message` (`id`);
CREATE TABLE `AO_message_forum` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`message_id` integer NOT NULL,
`forum_id` integer NOT NULL,
`status` integer NOT NULL,
`position` integer
)
;
ALTER TABLE `AO_message_forum` ADD CONSTRAINT `message_id_refs_id_68762267` FOREIGN KEY (`message_id`) REFERENCES `AO_message` (`id`);
ALTER TABLE `AO_message_forum` ADD CONSTRAINT `forum_id_refs_id_31073c3d` FOREIGN KEY (`forum_id`) REFERENCES `AO_forum` (`id`);
COMMIT;
这是django的sqlreset命令的输出:
BEGIN;
DROP TABLE `AO_user`;
DROP TABLE `AO_forum`;
CREATE TABLE `AO_forum` (
...
)
;
CREATE TABLE `AO_user` (
...
)
;
CREATE TABLE `AO_message` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`date` datetime NOT NULL,
`content_file` varchar(48) NOT NULL,
`summary_file` varchar(48) NOT NULL,
`user_id` integer NOT NULL,
`thread_id` integer,
`lft` integer NOT NULL,
`rgt` integer NOT NULL
)
;
ALTER TABLE `AO_message` ADD CONSTRAINT `user_id_refs_id_12d253fe` FOREIGN KEY (`user_id`) REFERENCES `AO_user` (`id`);
ALTER TABLE `AO_message` ADD CONSTRAINT `thread_id_refs_id_12262c89` FOREIGN KEY (`thread_id`) REFERENCES `AO_message` (`id`);
CREATE TABLE `AO_message_forum` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`message_id` integer NOT NULL,
`forum_id` integer NOT NULL,
`status` integer NOT NULL,
`position` integer
)
;
ALTER TABLE `AO_message_forum` ADD CONSTRAINT `message_id_refs_id_68762267` FOREIGN KEY (`message_id`) REFERENCES `AO_message` (`id`);
ALTER TABLE `AO_message_forum` ADD CONSTRAINT `forum_id_refs_id_31073c3d` FOREIGN KEY (`forum_id`) REFERENCES `AO_forum` (`id`);
CREATE INDEX `AO_message_user_id` ON `AO_message` (`user_id`);
CREATE INDEX `AO_message_thread_id` ON `AO_message` (`thread_id`);
CREATE INDEX `AO_message_forum_message_id` ON `AO_message_forum` (`message_id`);
CREATE INDEX `AO_message_forum_forum_id` ON `AO_message_forum` (`forum_id`);
COMMIT;
仅生成论坛和用户的删除命令。同样令人困惑和可能相关的是,当创建表时,我的Django项目名称(“AO”)附加在论坛和用户表的所有大写字母中,但是以小写形式附加到message和message_forum表(没有删除的表)命令)。
答案 0 :(得分:0)
使用此
heroku pg:reset SHARED_DATABASE --confirm my_great_app
将my_great_app
替换为您的应用名称