(I’m reporting my solution because my question said to be a duplicate)
Ah ok I figured it out and will post the solutions for anyone attempting to do the same thing.
This solution assumes that you want to create new models.
First create a new folder to store your files. We’ll call it “standAlone”. Within “standAlone”, create the following files:
init.py
myScript.py
settings.py
Obviously “myScript.py” can be named whatever.
Next, create a directory for your models.
We’ll name our model directory “myApp”, but realize that this is a normal Django application within a project, as such, name it appropriately to the collection of models you are writing.
Within this directory create 2 files:
init.py
models.py
Your going to need a copy of manage.py from an either an existing Django project or you can just grab a copy from your Django install path:
django\conf\project_template\manage.py
Copy the manage.py to your /standAlone directory. Ok so you should now have the following structure:
\standAlone
init.py
myScript.py
manage.py
settings.py
\myApp
init.py
models.py
Add the following to your myScript.py file:
from django.conf import settings
import os
os.environ[‘DJANGO_SETTINGS_MODULE’] = ‘settings’
from django.db import models
from myApp.models import
and add this to your settings.py file:
DATABASES = {
‘default’: {
‘ENGINE’: ‘django.db.backends.sqlite3’, # Add ‘postgresql_psycopg2’, ‘mysql’, ‘sqlite3’ or ‘oracle’.
‘NAME’: ‘test_django_orm.db’, # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
‘USER’: ‘’,
‘PASSWORD’: ‘’,
‘HOST’: ‘’, # Empty for localhost through domain sockets or ‘127.0.0.1’ for localhost through TCP.
‘PORT’: ‘’, # Set to empty string for default.
}
}
INSTALLED_APPS = (
‘myApp’
)
SECRET_KEY = ‘b&^=!i-&#rdx(_$q7lzcztew^3-5)v@igi%ug=)fd70m^9sb2’
and finally your myApp/models.py:
# myApp/models.py
from django.db import models
class MyModel(models.Model):
field = models.CharField(max_length=255)
and that’s it. Now to have Django manage your database, in command prompt navigate to our /standalone directory and run:
$python manage.py syncdb
Source
read