Saturday, December 9, 2017

Django Building a blog | Designing blog data Schema

Below is for Ubuntu.
  1. source djangoTestEnv/bin/activate
  2. cd Desktop
  3. django-admin startproject blogSite
  4. cd blogSite
  5. python startapp myBlog
  6. Go to blogSite/blogSite/ and add 'myBlog' in INSTALLED_APPS section. It should look similar to below
  7. Open blogSite/myBlog/ and paste content in this file
  8. Since is modified, we need to sync DB (migrate) to it. To do this, execute below commands
    cd blogSite (project root folder)
    python makemigrations myBlog

    output looks similar to below:
    Migrations for 'myBlog':
        - Create model Post

    This means Django just created   myBlog/migrations/ referring to our code in You can open this file and see how the migration looks like. 
  9. Execute below command to check SQL commands that Django executes
    python sqlmigrate myBlog 0001
  10. Apply migrations
    python migrate
  11. 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