Register an app on a Django project and ready the database
Previous: https://medium.com/@merajmasuk/start-a-django-project-from-scratch-d8ea06cabd01
- Start an app
$ django-admin startapp app1
2. Open project settings settings.py
. It should be inside the main project folder (i.e. project1).
$ nano project1/settings.py
and add the line ‘app1’ to the following part as shown
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app1',
]
3. Django has SQLite as default database solution. To use the database, we must first migrate the project related tables (i.e. admin, auth, contenttypes, sessions etc.) to the database.
$ python manage.py makemigrations
Migrate
$ python manage.py migrate
4. Create admin for the database and give user, email and password
$ python manage.py createsuperuser
5. Now whenever our app is running, we can access the admin panel for the SQLite database using the url http://localhost:8000/admin/
$ python manage.py runserver
Whenever any new changes made to our models in the Django project, we need to migrate.