Django 重置不删除表

发布于 2024-08-19 21:48:42 字数 3880 浏览 6 评论 0原文

我刚刚将我的开发环境从 Ubuntu Linux 迁移到 Mac OSX 雪豹。所有这些都可以在 Linux 上运行。在这两者上,我都使用 MySQL 作为 Django 的数据库。

Django 的重置功能不会为我的应用程序的所有模型发出放置命令。这是我的 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;

仅生成 Forum 和 User 的 drop 命令。同样令人困惑且可能相关的是,当创建表时,我的 Django 项目名称(“AO”)在论坛和用户表中全部大写,但在消息和 message_forum 表中以小写形式(这些是没有删除的表)命令)。

I just migrated my dev environment from Ubuntu Linux to Mac OSX snow leopard. All of this was working on Linux. On both, I have used MySQL for Django's db.

Django's reset function is not issuing drop commands for all of my app's models. Here is my models.py (with the Forum and User object fields removed for brevity):

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)

Here is the output of django's sql command:

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;

And here is the output of django's sqlreset command:

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;

Only drop commands for Forum and User are generated. Also confusing and possibly related is that when the tables get created, my Django project name ("AO") is appended in all caps for the forum and user tables, but in lowercase for the message and message_forum tables (which are the ones without drop commands).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

埋葬我深情 2024-08-26 21:48:42

使用此

heroku pg:reset SHARED_DATABASE --confirm my_great_app

替换 my_great_app 为您的应用名称

Use this

heroku pg:reset SHARED_DATABASE --confirm my_great_app

Replace my_great_app with your app name

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文