You have to chuck a thing in settings.py like this:
DATABASES = {'default': {'ENGINE': 'django.db.backends.postgresql','NAME': 'mydatabase','USER': 'mydatabaseuser','PASSWORD': 'mypassword','HOST': '127.0.0.1','PORT': '5432',}}
But don’t even trip about this atm. We’re using SQLite for now. Get back to this later.
Aaaaannnnd some of the default installed apps actually need a database so we’ve go to do some shit for that. Set it up using python manage.py migrate
Now we’re making those sweet sweet data structures. Open up models.py and edit that shit (inside the poll app ofc). You put in a thing this way:
class Question(models.Model):question_text = models.CharField(max_length=200)pub_date = models.DateTimeField('date published')
The way stuff is transformed is like this: - Model classes become: tables - fields become: columns - field names become: column names - field types become: column types - There are also a bunch of arguments you can give Fields: - A human readable name - default value - more shit… (max length, etc)
Go configure the stuff to your heart’s content!!!
Oh also add your app to the installed apps:
INSTALLED_APPS = ['polls.apps.PollsConfig',...]
So you’ve got to include your “config” class for your app in installed apps. In this case that’s in polls/apps.py and the class is called PollsConfig.
K. Now do a “make migration”, this creates a pending database change basically.
python manage.py makemigrations polls
Obviously you got to include the app you’re making the migration for in the command.
When you run makemigrations for an app, data for that get stored in appname/migrations
This cool command shows you the sql the migration generates: python manage.py sqlmigrate polls 0001