13. Blog app - syncdb A
In this chapter, we're going to use sqlite3 as a follow-up for the model setup in previous chapter.
When we look at the project file, we do not have any database even though we setup database in settings.py.
We need to issue syncdb command:
$ python manage.py syncdb Creating tables ... Creating table django_admin_log Creating table auth_permission Creating table auth_group_permissions Creating table auth_group Creating table auth_user_groups Creating table auth_user_user_permissions Creating table auth_user Creating table django_content_type Creating table django_session You just installed Django's auth system, which means you don't have any superusers defined. Would you like to create one now? (yes/no): yes Username (leave blank to use 'k'): Email address: k@bogotobogo.com Password: Password (again): Superuser created successfully. Installing custom SQL ... Installing indexes ... Installed 0 object(s) from 0 fixture(s) (DjangoVirtualenv)k@HP-Notebook:~/Django/DjangoVirtualenv/DjangoTestProject$
What we've done?
Let's use SQLite Database Browser to see what's been changed.
Open our database: db.sqlite3:
Strangely, we cannot find any data for us, it should be something "blog..."
We did syncdb after we modified models.py
Why is it?
The reason is we haven't told Django that we have an app.
Let's look the settings.py again, and this time, we should look for "INSTALLD_APPS":
# Application definition INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'blog', )
We added our app "blog".
Now, we do syncdb again:
$ python manage.py syncdb Creating tables ... Creating table blog_blog Installing custom SQL ... Installing indexes ... Installed 0 object(s) from 0 fixture(s)
When we look into the SQLite Database Browser again, we can see the blog is there:
We see all the fields we've written to the models.py. Also, notice that the id is there because Django puts that field for us.
Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization