Forums

Migrations not migrating django

Hello,

Many new user problems here:

Got the code from my repo and went with an inititial migration for the models:

(module_one-virtualenv) 23:35 ~/module_one (master)$ python manage.py makemigrations

    Migrations for 'dirt':
      dirt/migrations/0001_initial.py
        - Create model All_Data
        - Create model Beaches
        - Create model Codes
        - Create model Finance
        - Create model References
        - Create model SLR_Beaches
        - Create model SLR_Data
        - Create model SLR_Density

Looks good here but then when I go to migrate:

(module_one-virtualenv) 23:35 ~/module_one (master)$ python manage.py migrate                                                                 
System check identified some issues:
WARNINGS:
?: (mysql.W002) MySQL Strict Mode is not set for database connection 'default'
        HINT: MySQL's Strict Mode fixes many data integrity problems in MySQL, such as data truncation upon insertion, by escalating warnings 
into errors. It is strongly recommended you activate it. See: https://docs.djangoproject.com/en/2.0/ref/databases/#mysql-sql-mode
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, dirt, sessions
Running migrations:
  No migrations to apply.

How do I set strict mode ? And is that really keeping the migrations from happening?

Thanks

That looks like a new warning in Django 2.0 -- you can read the documentation here. The upshot appears to be that you need to add an init_command to your default database setting -- see here for an example.

you guys are good... i spent some time looking for that last night (this am)...

Glad we could help :-)

Thanks for this post! Excellent

I tried this.

I have two apps in my project (3 tables in total). I was earlier getting the 'strict mode' warning but the init_command change did not resolve that for me. After adding 'sql_mode': 'traditional' the strict mode warning has gone away.

However, I cannot migrate my database and get the message "No migrations to apply."

I have tried editing my models.py in both apps but changes are not getting detected.

How do I resolve this?

Thanks.

Could you share some more details of the code and the output you are getting on each stage?

I've successfully created the database but unable to migrate database and create tables.

The commands I ran were:

(myvirtualenv) 10:28 ~/Register_django (master)$ python manage.py makemigrations
No changes detected
(myvirtualenv) 10:34 ~/Register_django (master)$ python manage.py migrate                                                                                   
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
No migrations to apply.

My project contains two apps: registration and main, each with their own models.py

MySQL output below:

mysql> show tables;
+-------------------------------------+
| Tables_in_GeoMeteoMe$startvoting_db |
+-------------------------------------+
| auth_group                          | .
| auth_group_permissions              |
| auth_permission                     |
| auth_user                           |
| auth_user_groups                    |
| auth_user_user_permissions          |
| django_admin_log                    |
| django_content_type                 |
| django_migrations                   |
| django_session                      |
+-------------------------------------+
10 rows in set (0.01 sec)

Update: fixed it!

Had to run:

python manage.py makemigrations <app_name>

for each of my apps within the project.

This followed by

python manage.py migrate

seems to have fixed it...phew!

Hi there. When I called "python manage.py migrate" I got the warning "?: (mysql.W002) MySQL Strict Mode is not set for database connection 'default'" and after searching found this page.

I saw the post by giles (https://www.pythonanywhere.com/forums/topic/12609/#id_post_48595), and I read the example.

According to that example we can add "SET sql_mode='STRICT_TRANS_TABLES', innodb_strict_mode=1;" to our django settings file, but this will add a round trip to server for each connection, and "it’s better that you set it permanently for the server with SET GLOBAL and a configuration file change.".

To set it in the server I opened pythonanyware console to my mysql database.

I issued the command "SET sql_mode='STRICT_TRANS_TABLES', innodb_strict_mode=1;" in that console successfully.

But I think what I actually need is to issue "SET GLOBAL sql_mode='STRICT_TRANS_TABLES', innodb_strict_mode=1;". When I issue this command it I get the error "ERROR 1227 (42000): Access denied; you need (at least one of) the SUPER privilege(s) for this operation". Then I need to issue "SET @@GLOBAL.sqlmode=..." which gives the same error.

I also need "a configuration file change", which does not tell me what to do exactly. From the linked mysql document (https://dev.mysql.com/doc/refman/8.0/en/using-system-variables.html), I believe I need to issue "SET PERSIST sql_mode='STRICT_TRANS_TABLES', innodb_strict_mode=1;". But when I issue it I get "ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'sql_mode='STRICT_TRANS_TABLES', innodb_strict_mode=1' at line 1"

hmm- I believe that you cannot set that global on MySQL, as we don't give you the permissions to change the global settings.