domingo, 1 de septiembre de 2013

Create from existing database

Ever wanted to use an old, existing, legacy database with a Django Project? That’s totally possible!
Django allows you to create a file based on an existing database. To do this, you first have to make sure your database settings are properly specified in the file. Here’s an example of what the database settings in your file should look like:

DATABASE_ENGINE = ‘mysql’ # ‘postgresql_psycopg2′, ‘postgresql’, ‘mysql’, ’sqlite3′ or ‘oracle’.

DATABASE_NAME = ‘YourDataBaseName’ # Or path to database file if using sqlite3.
DATABASE_USER = ‘YourDataBaseUser’ # Not used with sqlite3.
DATABASE_PASSWORD = ’YourVerySecretPassword’ # Not used with sqlite3.
DATABASE_HOST = ” # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = ” # Set to empty string for default. Not used with sqlite3.

Then, from the command line, type:

python mysite/ inspectdb > mysite/myapp/

That should be all! Django created a for you, based on the contents of the existing database.


No hay comentarios:

Publicar un comentario