I have a brand new MariaDB serve (version: 5.5.41-MariaDB) and created a new database for my Django (1.8.2) application. The database was created using innoDB by default.
I have a model that looks like this:
class UserProfile(models.Model):
user = models.OneToOneField(User, unique=True) # django's default user model
When I run python manage.py migrate. I get the following error:
File "/home/vagrant/envs/leo/lib/python2.7/site-packages/MySQLdb/cursors.py", line 205, in execute
self.errorhandler(self, exc, value)
File "/home/vagrant/envs/leo/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
django.db.utils.OperationalError: (1005, "Can't create table 'leo.#sql-bcd_1f' (errno: 150)").
What am I doing wrong and how can I fix it?
This error can also occur when you don't make the migration files. Be sure to run makemigrations
before actual migration.
python manage.py makemigrations <app_name>
python manage.py migrate
I had the same problem under django 1.8, the only difference is that I'm using MySQL and not MariaDB.
Changing the database's encoding from utf8_unicode_ci to utf_general_ci solved the problem for me.
This bizarre MySQL error is explained here. I'm not sure how your Django app is triggering it though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With