Sometimes I write, sometimes it's worth reading. Check it out below.
I have several Django apps which are hosted on a Digital Ocean droplet, with development being done on my local Mac. For the most part, the initial SQLite setup works well, but for one of my larger projects I wanted to incorporate the use of MySQL. Here's how I went about the migration process:
Pre-Requisites
Recommended
Setup the MySQL Database
The Digital Ocean tutorial How to Create a Django App and Connect it to a Database was very helpful helpful here. In a nutshell:
Open the my.cnf file for editing: vim ~/.my.cnf
and add the following:
[client] user = USERNAME password = PASSWORD detault-character-set = utf8
A couple of notes here:
First of all, the possible locations of the my.cnf
file can be found via the following comand: mysql --help | grep "Default options" -A 1
. Since this is for development purposes only, and to avoid any permission issues, I've chosen the simplest location within the user home directory.
Second, the setting default-character-set value in the tutorial was actually utf-8
, not utf8
. For whatever reason that tutorial value was causing "invalid character set" exceptions to be thrown when attempting to connect (though the alias in the Index.xml file should have sufficed). Regardless, the workaround was to use the exact name, utf8
Third, the tutorial indicates to set the database within the my.cnf file. This caused issues with running mysqldump later, so I found it better to remove it from the my.cnf file, and add it within the name property of the DATABASES setting with Django.
Install mysqlclient Package
Next we'll need to install the mysqlclient package. You can do this via pip individually, or via requirements file:
# requirements.txt ... mysqlclient==2.1.0
Then install via pip:
(venv) $ pip install --upgrade pip (venv) $ pip install -r requirements.txt
When doing this initially however, I ran into what seemed to be an egg issue which resulted in a "No matching distribution found for mysqlclient" exception. What ended up being the issue was a lack of Python 3 headers for the install mysql version, and this was resolved by following the "Install" instructions within the PyPi mysqlclient page. After that, the pip install worked fine.
Update Django DATABASES Settings within settings.py
Next we'll take the existing default database Django settings and re-define them as legacy so we can continue to reference them, while defining MySQL as our new default database. Note that we add the 'NAME' attribute for the database, since we didn't define it within my.cnf. Also note that the username segment of the read_default_file value needs to be changed to reflect the actual user directory on your computer.
DATABASES = { 'legacy': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3', }, 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'DATABASE', 'OPTIONS': { 'read_default_file': '/Users/username/my.cnf', }, }, }
Run Database Migrations Against MySQL Database
Run the following to build out the database tables within the newly created "default" MySQL database: (venv) $ python manage.py migrate --settings path.to.settings --database default
Dump Existing Data
To transfer the from one datbase to the other, I used the dumpdata and loaddata commands from Django fixtures.
To dump the existing SQLite data:
(venv) $ python manage.py dumpdata --settings path.to.settings --database legacy -o data.json --exclude contenttypes
Note that I excluded contenttypes here, as including that data was causing integrity errors later with loaddata.
Then, load the data into the "default" MySQL database:
(venv) $ python manage.py loaddata data.json --settings path.to.settings --database default
If all went well, you should be able to startup a development server and browse around your site. Be sure to run tests to ensure everything migrated properly. When all looks good, it's probably also a good idea to remove the legacy database settings and file.
Links:
My wife's been shaking her head at me the past few months as I was slowly but surely converting our DVD collection to our home Synology Diskstation NAS. This was particularly because we had a super old Apple TV, and could only stream them via Airplay. The quality and interface was.. not so great.
However, for our anniversary I bought the latest generation Apple TV, installed Plex (on both the Apple TV and NAS), and via the below tutorial, was able to setup a streaming interface of our DVD collection better than I could have imagined:
https://www.youtube.com/watch?v=Z7LfXVVfYhI
There was only one wrinkle in my setup however: I wanted to keep our videos under /Volume1/video/* as opposed to /Volume1/Plex/Library/*, especially because keeping them in the former location allowed us to continue to stream videos on our phones and iPad via DS File, while Plex allows only free streaming to Apple TV.
So the obvious solution was to create symlinks from video/* to Library/*. However when doing so, Plex could see the directory but not access it. Searching Google showed various hacks to enable Plex access, but the actual solution was quite simple: the plex user on the Synology Diskstation simply needed read access to the video/* directory.
Super simple, and worked like a charm. Happy streaming!
This article is more of a cheat-sheet for myself, and less of a public facing post, but hopefully it can help someone else out.
Install and Start MySQL
Install MySQL using Homebrew: brew install mysql
If MySQL has not been added to the system path, run the following: export PATH=$PATH:/usr/local/mysql/bin
Create a User, Privileges and Password
Login to mysql as root: mysql -u root
Create user: mysql> CREATE USER 'username'@'localhost';
Grant all privileges: mysql> GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost';
Run the following:
mysql> USE mysql; mysql> UPDATE user SET authentication_string='password' WHERE User='username'; mysql> FLUSH PRIVILEGES; mysql> quit;
Alternatively (as of version 8.0.15), the password can be updated:
mysql> USE mysql; mysql> ALTER USER 'username'@'localhost' IDENTIFIED BY 'password'; mysql> FLUSH PRIVILEGES; mysql> quit;
You now should be good to create a local database connection for the newly created username.
Create Database
mysql> CREATE DATABASE databasename;
Delete Database
mysql> DROP DATABASE databasename;
One year ago, I was riding pretty high. Well, at least website wise. I'd successfully migrated my old Wordpress site from Bluehost to my Synology Diskstation. It was a little painful at first, but eventually I was able to successfully serve my own website from my own home.
There were some initial tradeoffs during that initial process of course. I wasn't able to peform a total rebuild in Django as I'd intended, due to the NAS being more configured for Wordpress hosting and any alterations to the serving configs could be wiped out by an update. So I settled for Wordpress for my own site, and was still able to install and use Python/Django for some side projects. Things were pretty great.
Then one morning, I was greeted in my office with the dreaded "System Crash" beeps. My volume had crashed, and I'd lost all my site data on the NAS. And I thought, "Aha, lesson learned: always backup your ish." Thankfully I had my Bluehost Wordpress backup, as well as some project stuff in git and was able to rebuild with minimal data loss. And I conigured a pretty thorough redundant backup system to prevent another such loss.
I did say *pretty* thorough, because of course it happened again. And I found I hadn't redundantly back-ed up everything. So my next lesson was, "Just because you can serve things on from a home NAS doesn't mean you should." It's simply not optimized for web hosting, installing packages was a pain, and I suppose there's no telling whether the crashes were just fate, or malicious. In any event, I swam for the open waters of Digital Ocean.
And it's been pretty good so far. Setting up a Django site was a breeze, and it sure feels nice to be free from the structures of Synology and bloat of Wordpress. Obviously it's a work in progress: the design so far is bare HTML and restoring and re-routing my old posts will be a bit of an adventure. But I'm looking forward to it!
Every December for as long as I can remember, we’d eagerly retrieve our Christmas decorations from their long-boxed-up slumber. Probably the most prized of which were our Santa Claus dinner placemats, which depicted various scenes of St. Nick, Mrs. Claus, elves and reindeer all prepping for their Yuletide escapades. A little internet sleuthing revealed that these scenes were actually illustrations commissioned for a children’s book by the name of “Jolly Old Santa Claus,” painted by German/American artist George Hinke.
From the Museum of Wisconsin Art Website:
George Hinke was born in Berlin, Germany, in 1883 and schooled in a classic style of painting. Mr. Hinke came to Milwaukee, Wisconsin, in 1923, where he worked at a printing shop until he opened his own studio. From 1944 until Mr. Hinke’s death in 1953, Ideals commissioned him to create many works of art. In addition to Santa Claus, Mr. Hinke’s subjects included American small-town life, American flags, and religious scenes – all in his classic, nostalgic style. The paintings in the 1961 Ideals Magazine Collector’s Edition of Jolly Old Santa Claus are rendered in oil on stretched canvas. The influence of Mr. Hinke’s German background is evident in the Santa Claus series: from Santa’s castle, which resembles the castles of Bavarian King Ludwig, to the Black Forest clock on the wall of Santa’s workshop to the elves themselves, who are reminiscent of those characters in stone that decorate many German gardens.
For me, these placemats provided the archetypal representation of what Santa Claus looked like — er, I mean — looks like, and all the little details were so fun and interesting to us as children. We still use them at mom and dad’s every year, and though the book can still be found easily enough through retailers like Amazon and Thriftbooks, actual full prints of the scenes are difficult to find. Thus I wanted to share them here for everyone to enjoy.
I’ve uploaded them here as HD photos taken with my iPhone 6 and cropped in GIMP. At some point perhaps I will use my limited photo-editing skills to restore some of the color and hide some of the placemat defects. But for now: Merry Christmas to all, and to all a good night!
UPDATE: Just a quick note that I had these photos (without any further editing) made into place mats via Snapfish. The process was super simple and the results were fantastic. I highly recommend it! Just be sure to use the Honey app or some other promo code provider to avoid paying the steep full price. I had 8 made for $65.
<head>
block: <link rel="shortcut icon" href="favicon.ico" />