4

I' ve a Django application which has been upgraded recently from 1.4.5 to 1.11.16. It was running on an older version of debian linux, which has been reinstalled and is now 9.6 . Originally the database was mysql (default debian installation), and now it' s mariadb (also default installation) .

Since the projects are small, there were basically no db optimization, almost everything was running with the default settings. Before the reinstall and upgrade the db has been dumped and later loaded. Originally it was using myisam table types, but now the default is innodb.

Whenever i' m trying to create a new table (django model) with the simpliest setup, e. g.:

class Sth(models.Model):
    car = models.CharField(max_length=128)

i face the following warning:

/home/user/.virtualenvs/prj/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py:101: Warning: Field 'name' doesn't have a default value

return self.cursor.execute(query, args)

. What does it mean, and why is it appearing? If strict mode is set, it even turns to be an error.

What would be the solution for this problem? Knowing the change of the debian system (mysql -> mariadb) and django upgrade (1.4.5 -> 1.11.16) what should i think of?

I also tried changing the current tables to innodb, and also change the default mariadb type to myisam, but it does not help.


The sql queries from the mysql log at the time of running the migration:

CREATE TABLE `infokom_sth` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `car` varchar(128) NULL)
INSERT INTO `django_migrations` (`app`, `name`, `applied`) VALUES ('infokom', '0004_sth', '2019-03-05 22:25:54.360285')
INSERT INTO `django_content_type` (`app_label`, `model`) VALUES ('infokom', 'sth')
INSERT INTO `auth_permission` (`name`, `content_type_id`, `codename`) VALUES ('Can add sth', 27, 'add_sth'), ('Can change sth', 27, 'change_sth'), ('Can delete sth', 27, 'delete_sth')
user2194805
  • 1,201
  • 1
  • 17
  • 35

1 Answers1

1

The error is coming up while Django is running the query INSERT INTO django_content_type (app_label, model) VALUES ('infokom', 'sth') because it's not specifying the column name.

In earlier versions of Django, there was a column name on the table django_content_type, but it got removed sometime between 1.4 and 1.10.

The migrations didn't remove the extra column, so you have to remove django_content_type.name manually.

I was getting the same error on 1.10, then removed django_content_type.name and then the migrations worked fine for me.

thespacecamel
  • 912
  • 11
  • 14