管理。django模型的py sql命令

时间:2021-01-19 23:19:18

just wondering... but is it possible to generate SQL commands for django's models?

只是想知道…但是,是否可能为django的模型生成SQL命令呢?

e.g. the session model

例如,会话模式

python manage.py sql django

Any ideas?

什么好主意吗?

2 个解决方案

#1


7  

You need to mention the name of the specific app that comes with django, such as

您需要提到django附带的特定应用程序的名称,例如

 python manage.py sql auth
 python manage.py sql admin

I find it a bit clumsy that you can't give fully-qualified names (such as django.contrib.auth), but using just the last part of the name seems to work fine.

我发现你不能给出完全限定的名称(例如django.b.auth),但是使用这个名称的最后一部分似乎没问题。

#2


0  

This is no longer possible with django migrations (django>=1.7). The sql management command is no longer available.

这在django迁移中不再可能实现(django>=1.7)。sql管理命令不再可用。

Though it operates slightly differently, the sqlmigrate management command can be used to find the sql commands for individual migrations.

尽管它的操作略有不同,但是sqlmigrate management命令可以用于为单个迁移查找sql命令。

./manage.py sqlmigrate auth  0001
./manage.py sqlmigrate auth  0002
...

#1


7  

You need to mention the name of the specific app that comes with django, such as

您需要提到django附带的特定应用程序的名称,例如

 python manage.py sql auth
 python manage.py sql admin

I find it a bit clumsy that you can't give fully-qualified names (such as django.contrib.auth), but using just the last part of the name seems to work fine.

我发现你不能给出完全限定的名称(例如django.b.auth),但是使用这个名称的最后一部分似乎没问题。

#2


0  

This is no longer possible with django migrations (django>=1.7). The sql management command is no longer available.

这在django迁移中不再可能实现(django>=1.7)。sql管理命令不再可用。

Though it operates slightly differently, the sqlmigrate management command can be used to find the sql commands for individual migrations.

尽管它的操作略有不同,但是sqlmigrate management命令可以用于为单个迁移查找sql命令。

./manage.py sqlmigrate auth  0001
./manage.py sqlmigrate auth  0002
...