Reputation: 3491
Is it possible to take advantage of migrations when I use only Django ORM but not the whole Django engine? I mean, I found somewhere in Internet that script:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from django.conf import settings
settings.configure(
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'roma_db',
'USER': 'root',
'PASSWORD': 'qweqweqwe'
}
},
INSTALLED_APPS = ('south')
)
from django.db import models
class Game(models.Model):
url = models.TextField()
title = models.TextField()
description=models.TextField()
def __unicode__(self):
return self.title
class Meta:
app_label = ''
def create_table(cls):
from django.db import connection
from django.core.management.color import no_style
sql, references = connection.creation.sql_create_model(cls, no_style())
cursor = connection.cursor()
for q in sql:
try:
cursor.execute(q)
except:
pass
def main():
create_table(Game)
if __name__ == "__main__":
main()
And it works perfect for my needs until I want to migrate DB. As I dont have manage.py
- I dont know what to do.
Upvotes: 1
Views: 440
Reputation: 15738
Sure you can use any part of Django you find useful without having to go full way making a true Django project.
It's quite common to have a custom application (often in PHP) and Django admin used to manage database. The same way you can use South (ie migrations), or template engine, or whatever you find useful without having to write complete site (i.e. with URL patters, views etc).
E.g. for using South, first you need to start a blank project as you will need manage.py and settings anyway:
django-admin.py startproject <projectname>
Then, start a new app and write your initial models manually or generate them using inspectdb:
python manage.py inspectdb > models.py
Add your app and south to settings.INSTALLED_APPS, and that's it, you can change models and apply changes with
manage.py migrate <appname>
Upvotes: 2
Reputation: 29967
You don't have to use the complete Django stack (i.e. templating, URL resolving etc.), but you will probably have to create a Django application as South works on applications. You could cram all necessary code in a single file with some trickery (this post explains how), but IMHO it is not worth the effort. Just create a proper application as a module with a models.py
file.
You don't need a manage.py, as you can run management commands from your code.
Upvotes: 1