Created
February 16, 2011 19:40
-
-
Save themartorana/830010 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# | |
def create_table_for_unrelated_model(model, database_name): | |
from django.db import connections, transaction | |
from django.core.management.sql import custom_sql_for_model | |
from django.core.management.color import no_style | |
connection = connections[database_name] | |
cursor = connection.cursor() | |
if not model._meta.managed: | |
model._meta.managed = True | |
sql, references = connection.creation.sql_create_model(model, no_style()) | |
if sql and len(sql) > 0: | |
sql_to_execute = sql[0] | |
cursor.execute(sql_to_execute) | |
transaction.commit_unless_managed(using=database_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment