flush database

Date: March 23rd 2016
Last updated: March 23rd 2016

As I was creating a web framework I occasionally messed things up and needed to start from scratch. The first time I managed to create several errors by using unique = True and assigning multiple duplicate keys. The second time was on trying to link a registered user with a user profile. Regardless of flushing the database using python manage.py the errors persisted. So I started from scratch. Here's what I did to get back up and running.

The most recent error occured in models.py
It turns out the reason for this error is because a user cannot reference a profile before it exists. For more info see this article: https://www.fusionbox.com/blog/detail/django-onetoonefields-are-hard-to-use-lets-make-them-better/551/

from django.contrib.auth.models import User

class Surfer(models.Model):
    user = models.OneToOneField(User)

command line inside project (bash)

# CAUTION: Theres no going back after this!!
python3 manage.py flush #<=== not required if using the following step *mysql db rebuild*
# Find all migration files
# source: http://stackoverflow.com/questions/26283159/django-1-7-migrations-how-do-i-clear-all-migrations-and-start-over-from-scrat
find . -path *migrations* -name "*.py" -not -path "*__init__*"
# Remove all migration files
find . -path *migrations* -name "*.py" -not -path "*__init__*" -exec rm {} \;

mysql db rebuild

mysql -u root -p
#<enter password>
DROP DATABASE surfdiary;
SHOW DATABASES; #check the db was removed
CREATE DATABASE surfdiary;
#<recreate user and host>
GRANT all ON surfdiary.* TO 'duck'@'localhost' IDENTIFIED BY 'lamaslayer99';
FLUSH PRIVILEGES;
exit

command line inside project (bash)

# recreate project database
python3 manage.py migrate
python3 manage.py makemigrations surferprofile
python3 manage.py migrate
python3 manage.py createsuperuser
# follow the prompts

results matching ""

    No results matching ""