Below is for Ubuntu.
If you enjoyed this post, make sure you subscribe to my RSS feed! Comments are encouraged
- source djangoTestEnv/bin/activate
- cd Desktop
- django-admin startproject blogSite
- cd blogSite
- python manage.py startapp myBlog
- Go to blogSite/blogSite/settings.py and add 'myBlog' in INSTALLED_APPS section. It should look similar to below
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myBlog',
] - Open blogSite/myBlog/models.py and paste content in this file
- Since models.py is modified, we need to sync DB (migrate) to it. To do this, execute below commands
cd blogSite (project root folder)
python manage.py makemigrations myBlog
output looks similar to below:
Migrations for 'myBlog':
myBlog/migrations/0001_initial.py
- Create model Post
This means Django just created myBlog/migrations/0001_initial.py referring to our code in models.py. You can open this file and see how the migration looks like. - Execute below command to check SQL commands that Django executes
python manage.py sqlmigrate myBlog 0001 - Apply migrations
python manae.py migrate - For any change in models, we need to apply migrations again just like above.
If you enjoyed this post, make sure you subscribe to my RSS feed! Comments are encouraged
No comments:
Write comments