create database backend

Date: March 16th 2016
Last updated: March 16th 2016

The database behind the web framework is important for interactive design. It separates this framework from other options like hosting a site from Github using html, css and javascript.

modify mysite/settings.py

#< snipped >
# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'surfdiary',
        'USER': 'duck',
        'PASSWORD': 'lamaslayer99',
        'HOST': '%',
    }
}
#< snipped >

sign into mysql as root (opens mysql shell)

mysql -u root -p

check databases and users

SHOW DATABASES;
# check users
SELECT host, user, password FROM mysql.user;

create user, database and grant privileges

CREATE DATABASE surfdiary;
CREATE USER duck;
GRANT all ON surfdiary.* TO 'duck'@'localhost' IDENTIFIED BY 'lamaslayer99';
FLUSH PRIVILEGES;

install dependencies to virtualenv (bash command line)

sudo pip3 install mysqlclient
sudo apt-get install python3-dev libmysqlclient-dev

migrate database (bash command line)

python3 manage.py migrate

## output
Operations to perform:
  Apply all migrations: auth, contenttypes, admin, sessions
Running migrations:
  Rendering model states... DONE
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying sessions.0001_initial... OK

database schema (created mostly by default) code used to generate schema (slightly different to SQLite example)

# !#/bin/bash
# Contents of mybashfile.sh

# SchemaCrawler
SchemaCrawlerPATH=/home/ray/Programs/schemacrawler-14.07.03-main

# path to database
DatabaseFILE='surfdiary'

# The type of database system
RDBMS=mysql

# Where to store the image
OutputPATH=~/Devel/surfdiary/schema_diagram/ER.png

# Username and password
USER='duck'
PASSWORD='lamaslayer99'

java -classpath $(echo ${SchemaCrawlerPATH}/_schemacrawler/lib/*.jar | tr ' ' ':') \
schemacrawler.Main -server=${RDBMS} -database=${DatabaseFILE} -outputformat=png \
-outputfile=${OutputPATH} -command=graph -infolevel=maximum \
-user=${USER} -password=${PASSWORD}

results matching ""

    No results matching ""