Django 1.9 How to Setup ORM Models (Pycharm)

In this tutorial I will assume that you are using the Django module you created when you started the project (though it can be modified slightly if its a different module)


I will assume that myapp is that original module you created and is where your ORM models are.

Step 1:
Ensure that you list myapp under INSTALLED_APPS list in It is not there by default!

Step 2:
Ensure that on top of you have the following import
from django.db import models

Also as part of step 2 you may need other imports to use some of the default tables that come with Django. For example, I always use the auth_user table which requires:
from django.contrib.auth.models import User

Table Generation (Made Easy?)
Step 1:
In ensure you have the following code snippet present since it is defaulted as false
migrated = True

Step 2:
Run the following in command line from the project’s directory. You may need sudo privileges. Remember to change myapp to your app’s name.
./ makemigrations
You may be required to specify myapp after makemigrations

Step 3:
You will have noticed that the above command would have made a directory migrations with file(s) in it.

The directory should have changed to look like this

– migrations
– –

A file similar to the above will be generated, there is an option to name the file which can be found in the references.

Finally, run the following to have your tables generated in the database
./ migrate

Model Meta Options – Discusses managed option
Django Models – Contains instructions for using models
Using migration to generate your tables

Leave a Reply