Issue: MySQL not included in Travis CI
Author: foxx
State: closed
Created: 2016-01-10 20:06:30

Just looking over [`.travis.yml`](https://github.com/coleifer/peewee/blob/master/.travis.yml), and it appears that MySQL is not included in the backend tests.

Any particular reason for this, or would a PR fix be accepted?


Added this. MySQL has always been a 2nd-class citizen since I don't use it and don't typically even have it installed. I've added it, however, so let's hope things work!


Well, lots of issues... reopening to fix.


Admittedly MySQL is a flawed technology in comparison with Postgres, but fwiw MariaDB is a fantastic improvement and also backwards compatible with Oracle/Percona MySQL, right down to the binlogs. 

Figured there would probably be a lot of failed tests. I can contribute a couple of hours next week to help get this working if needed (if so, just let me know where you'd like me to focus efforts)


These appear to be the two errors:

```
======================================================================
ERROR: test_add_not_null (playhouse.tests.test_migrate.MySQLMigrationTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/coleifer/peewee/playhouse/tests/test_migrate.py", line 278, in test_add_not_null
    dob=None)
  File "/opt/python/2.7.9/lib/python2.7/unittest/case.py", line 473, in assertRaises
    callableObj(*args, **kwargs)
  File "/home/travis/build/coleifer/peewee/peewee.py", line 4493, in create
    inst.save(force_insert=True)
  File "/home/travis/build/coleifer/peewee/peewee.py", line 4679, in save
    pk_from_cursor = self.insert(**field_dict).execute()
  File "/home/travis/build/coleifer/peewee/peewee.py", line 3213, in execute
    cursor = self._execute()
  File "/home/travis/build/coleifer/peewee/peewee.py", line 2628, in _execute
    return self.database.execute_sql(sql, params, self.require_commit)
  File "/home/travis/build/coleifer/peewee/peewee.py", line 3461, in execute_sql
    self.commit()
  File "/home/travis/build/coleifer/peewee/peewee.py", line 3285, in __exit__
    reraise(new_type, new_type(*exc_args), traceback)
  File "/home/travis/build/coleifer/peewee/peewee.py", line 3454, in execute_sql
    cursor.execute(sql, params or ())
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/cursors.py", line 146, in execute
    result = self._query(query)
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/cursors.py", line 296, in _query
    conn.query(q)
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/connections.py", line 819, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/connections.py", line 1001, in _read_query_result
    result.read()
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/connections.py", line 1286, in read
    first_packet = self.connection._read_packet()
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/connections.py", line 965, in _read_packet
    packet.check_error()
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/connections.py", line 394, in check_error
    err.raise_mysql_exception(self._data)
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/err.py", line 120, in raise_mysql_exception
    _check_mysql_exception(errinfo)
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/err.py", line 112, in _check_mysql_exception
    raise errorclass(errno, errorvalue)
IntegrityError: (1048, u"Column 'dob' cannot be null")
======================================================================
ERROR: test_modify_not_null_foreign_key (playhouse.tests.test_migrate.MySQLMigrationTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/coleifer/peewee/playhouse/tests/test_migrate.py", line 315, in test_modify_not_null_foreign_key
    user=None)
  File "/opt/python/2.7.9/lib/python2.7/unittest/case.py", line 473, in assertRaises
    callableObj(*args, **kwargs)
  File "/home/travis/build/coleifer/peewee/peewee.py", line 4493, in create
    inst.save(force_insert=True)
  File "/home/travis/build/coleifer/peewee/peewee.py", line 4679, in save
    pk_from_cursor = self.insert(**field_dict).execute()
  File "/home/travis/build/coleifer/peewee/peewee.py", line 3213, in execute
    cursor = self._execute()
  File "/home/travis/build/coleifer/peewee/peewee.py", line 2628, in _execute
    return self.database.execute_sql(sql, params, self.require_commit)
  File "/home/travis/build/coleifer/peewee/peewee.py", line 3461, in execute_sql
    self.commit()
  File "/home/travis/build/coleifer/peewee/peewee.py", line 3285, in __exit__
    reraise(new_type, new_type(*exc_args), traceback)
  File "/home/travis/build/coleifer/peewee/peewee.py", line 3454, in execute_sql
    cursor.execute(sql, params or ())
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/cursors.py", line 146, in execute
    result = self._query(query)
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/cursors.py", line 296, in _query
    conn.query(q)
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/connections.py", line 819, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/connections.py", line 1001, in _read_query_result
    result.read()
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/connections.py", line 1286, in read
    first_packet = self.connection._read_packet()
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/connections.py", line 965, in _read_packet
    packet.check_error()
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/connections.py", line 394, in check_error
    err.raise_mysql_exception(self._data)
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/err.py", line 120, in raise_mysql_exception
    _check_mysql_exception(errinfo)
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/err.py", line 112, in _check_mysql_exception
    raise errorclass(errno, errorvalue)
IntegrityError: (1048, u"Column 'user_id' cannot be null")
----------------------------------------------------------------------
```


I'm not quite sure what's going on, those tests are passing locally for me.


Only had a few minutes spare to look at this, I think the problem might be because `pymysql` is raising it's own class of `IntegrityError` seen [here](https://github.com/PyMySQL/PyMySQL/blob/master/pymysql/err.py#L44).

Also note that your `assertRaises` is looking for `_exception_not_null_violation = OperationalError`, where as MySQL is raising `IntegrityError`.

So either;

A) assertRaises needs to look for `peewee.OperationalError`
B) assertRaises needs to look for `pymysql.OperationalError`
C) There is something wrong with `migrate.add_not_null`

As for why it's working locally, it could be due to differences in MySQL version (e.g. behaviour changes between 5.0 ~ 5.5), although 5.0 doesn't really need to be supported imho (it's as old as Python 2.6 iirc)


Alright, I believe this one is now fixed. Thanks for keeping me honest @foxx!


Awesome! I'm curious, what was the problem with this in the end?

PS) Lol @ dropping 3.2/3.3, that's what I had to do as well, it's not widely used so should be fine.


Ummmm, let's see. pymysql wasn't compat with 3.2/3.3. Then you were
correct, I just needed to catch both integrity/operational errors for mysql
for whatever reason.

On Thu, Jan 14, 2016 at 3:59 AM, Cal Leeming notifications@github.com
wrote:

> Awesome! I'm curious, what was the problem with this in the end?
> 
> PS) Lol @ dropping 3.2/3.3, that's what I had to do as well, it's not
> widely used so should be fine.
> 
> —
> Reply to this email directly or view it on GitHub
> https://github.com/coleifer/peewee/issues/811#issuecomment-171592148.


Doh sorry, I just realised you pushed the code to master, I would have checked the commit history myself if I had realised lol, my bad.