I am beginning a task and i have made the decision to make use of Django.

My real question is regarding to the development of the database. I have browse the tutorial plus some books and individuals begin creating the models, after which syncing the DataBase. I have to express, this is a little strange for me personally. I have always began using the DB, determining the schema, and then creating my DB Abstractions (models, organizations, etc).

I have check some exterior-pluggable applications and individuals use that "model first" practice too.

I can tell some advantages of the "model-first" approach, like portability, re-deployment, etc.

However i also see some disadvantages: how you can create indexes, the type of index, triggers, sights, SPs, etc.

So, How can you begin a real existence project?

Triggers, sights, and saved methods aren't really an element of the Django world. It may be made for their services, but it is painful and unnecessary. Django's designers go ahead and take view that business logic goes in Python, not inside your database.

For indexes, you may create them together with your models (with such things as db_index and unique_together, or add them later via database migrations using something similar to South.

Mostly we do not write SQL (e.g. create index, create tables, etc...) for the models, and rather depend on Django to create it for all of us.

It's absolutely okay to begin with creating your application in the model layer, as possible depend on Django to create the right database sql required for you.

However, Django provides various functions that you should replicate these database functions:

  • triggers: Django code or MySQL triggers
  • indexes: could be specified with db_index=True
  • unique constraints: unique = True or unique_togther = (('field1', field2'),) for composite unique constraint.

The benefit with using Django rather than writing sql is you abstract yourself from the particular database you're using. Quite simply, you may be on SQLite eventually and change to PostgresQL or MySQL the following and also the change could be relatively painless.

Example:

Advertising media are this:

python manage.py syncdb 

Django instantly produces the tables, indexes, triggers, etc, it must offer the models you've produced. If you're not confident with django creating your database for you personally, you could use:

python manage.py sqlall 

This can print the SQL claims that Django will have to have to ensure that its models to operate correctly. You will find other sql instructions to work with:

see: https://docs.djangoproject.com/en/1.3/ref/django-admin/#sql-appname-appname