Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
In this session we'll have a brief look at the settings.py file and do a migration for the saturn project.

To setup your database you need to give the credential in saturn/settings.py in the section:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}


As you see above the default database is set to sqlite3 and the NAME of the database is set to file path of db.sqlite3, if your database is set to MySQL you would have to provide the name of the database in NAME section.

ENGINE can have one of the below database bindings:

'django.db.backends.sqlite3',
'django.db.backends.postgresql',
'django.db.backends.mysql',
'django.db.backends.oracle'


If you are using a db other than sqlite like MySQL you should provide USER, PASSWORD HOST beside ENGINE and NAME.

INSTALLED_APPS is a section that contains apps used by
our project. For example for session management there is django.contrib.sessions section.

Some of these applications use database tables, so for Django apps to work properly, youn need to use migrate command
and create corresponding tables:

$ python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying sessions.0001_initial... OK


You can see that needed tables are created as above. In case you don't need an app just comment it out from INSTALLED_APPS before running migration.

The next session we would create models for our tables and would do the real parts. :)

#python #django #settings #INSTALLED_APPS #migration #database #ENGINE #django_part4