Flask & SQL Alchemy db.create_all() detect unicode returns: %r
Question: I'm trying to setup a sqlite database with Flask using SQLAlchemy according to
[the tutorial:](http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-
part-i-hello-world "The Flask Mega-Tutorial")

I get the following error when I try to run `db.create_all()`:

    
    
    (venv)[username@md projectname]$ python
    Python 2.7.9 (default, Jan 12 2015, 10:50:37) 
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from app import db
    /home/username/flask-project/projectname/venv/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py:800: UserWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True to suppress this warning.
      warnings.warn('SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True to suppress this warning.')
    >>> db.create_all()
    /home/username/flask-project/projectname/venv/lib/python2.7/site-packages/sqlalchemy/engine/default.py:298: SAWarning: Exception attempting to detect unicode returns: OperationalError('(sqlite3.OperationalError) near "\xf1\x90\x81\x93\xf1\x90\x81\x8c\xf5\x80\x81\x83\xf0\xb0\x80\xa0\xf4\xb0\x81\x81\xfa\x80\x81\x94\xfd\x80\x80\xa7\xfc\xb0\x81\xa5\xf8\x80\x81\xb4\xfb\x80\x81\xb0\xfa\x90\x81\xa1\xf8\x80\x81\xae\xf9\x90\x81\xb2\xfd\x90\x81\xb4\xfb\xa0\x81\xb2\xf9\xb0\x81\xb3\xf0\x90\x80\xa0\xf8\x80\x81\x93\xf0\x90\x81\x96\xf0\xb0\x81\x92\xf0\x90\x81\x88\xfa\x80\x81\x92\xfc\x80\x80\xb6\xfa\x90\x80\xa9\xf0\x90\x80\xa0\xf8\x80\x81\x93\xfb\xa0\x81\xa1\xfb\xa0\x81\xaf\xfc\x90\x81\x9f\xfe\x90\x80\x80": syntax error',)
      "detect unicode returns: %r" % de)
    /home/username/flask-project/projectname/venv/lib/python2.7/site-packages/sqlalchemy/engine/default.py:298: SAWarning: Exception attempting to detect unicode returns: OperationalError('(sqlite3.OperationalError) near "\xf1\x90\x81\x93\xf1\x90\x81\x8c\xf5\x80\x81\x83\xf0\xb0\x80\xa0\xf4\xb0\x81\x81\xfa\x80\x81\x94\xfd\x80\x80\xa7\xfc\xb0\x81\xa5\xf8\x80\x81\xb4\xfb\xa0\x81\xb5\xf8\xb0\x81\xa9\xf9\x80\x81\xaf\xf8\x80\x81\xa5\xf9\x90\x81\xb2\xfd\x90\x81\xb4\xfb\xa0\x81\xb2\xf9\xb0\x81\xb3\xf0\x90\x80\xa0\xf8\x80\x81\x93\xf0\x90\x81\x96\xf0\xb0\x81\x92\xf0\x90\x81\x88\xfa\x80\x81\x92\xfc\x80\x80\xb6\xfa\x90\x80\xa9\xf0\x90\x80\xa0\xf8\x80\x81\x93\xfb\xa0\x81\xa1\xfb\xa0\x81\xaf\xfc\x90\x81\x9f\xfc\xa0\x80\x80": syntax error',)
      "detect unicode returns: %r" % de)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/username/flask-project/projectname/venv/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 972, in create_all
        self._execute_for_all_tables(app, bind, 'create_all')
      File "/home/username/flask-project/projectname/venv/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 964, in _execute_for_all_tables
        op(bind=self.get_engine(app, bind), **extra)
      File "/home/username/flask-project/projectname/venv/lib/python2.7/site-packages/sqlalchemy/sql/schema.py", line 3695, in create_all
        tables=tables)
      File "/home/username/flask-project/projectname/venv/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1855, in _run_visitor
        with self._optional_conn_ctx_manager(connection) as conn:
      File "/usr/local/lib/python2.7/contextlib.py", line 17, in __enter__
        return self.gen.next()
      File "/home/username/flask-project/projectname/venv/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1848, in _optional_conn_ctx_manager
        with self.contextual_connect() as conn:
      File "/home/username/flask-project/projectname/venv/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 2039, in contextual_connect
        self._wrap_pool_connect(self.pool.connect, None),
      File "/home/username/flask-project/projectname/venv/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 2078, in _wrap_pool_connect
        e, dialect, self)
      File "/home/username/flask-project/projectname/venv/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1405, in _handle_dbapi_exception_noconnection
        exc_info
      File "/home/username/flask-project/projectname/venv/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 200, in raise_from_cause
        reraise(type(exception), exception, tb=exc_tb, cause=cause)
      File "/home/username/flask-project/projectname/venv/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 2074, in _wrap_pool_connect
        return fn()
      File "/home/username/flask-project/projectname/venv/lib/python2.7/site-packages/sqlalchemy/pool.py", line 376, in connect
        return _ConnectionFairy._checkout(self)
      File "/home/username/flask-project/projectname/venv/lib/python2.7/site-packages/sqlalchemy/pool.py", line 713, in _checkout
        fairy = _ConnectionRecord.checkout(pool)
      File "/home/username/flask-project/projectname/venv/lib/python2.7/site-packages/sqlalchemy/pool.py", line 480, in checkout
        rec = pool._do_get()
      File "/home/username/flask-project/projectname/venv/lib/python2.7/site-packages/sqlalchemy/pool.py", line 1151, in _do_get
        return self._create_connection()
      File "/home/username/flask-project/projectname/venv/lib/python2.7/site-packages/sqlalchemy/pool.py", line 323, in _create_connection
        return _ConnectionRecord(self)
      File "/home/username/flask-project/projectname/venv/lib/python2.7/site-packages/sqlalchemy/pool.py", line 454, in __init__
        exec_once(self.connection, self)
      File "/home/username/flask-project/projectname/venv/lib/python2.7/site-packages/sqlalchemy/event/attr.py", line 246, in exec_once
        self(*args, **kw)
      File "/home/username/flask-project/projectname/venv/lib/python2.7/site-packages/sqlalchemy/event/attr.py", line 256, in __call__
        fn(*args, **kw)
      File "/home/username/flask-project/projectname/venv/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py", line 1319, in go
        return once_fn(*arg, **kw)
      File "/home/username/flask-project/projectname/venv/lib/python2.7/site-packages/sqlalchemy/engine/strategies.py", line 165, in first_connect
        dialect.initialize(c)
      File "/home/username/flask-project/projectname/venv/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 256, in initialize
        self._check_unicode_description(connection):
      File "/home/username/flask-project/projectname/venv/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 343, in _check_unicode_description
        ]).compile(dialect=self)
    sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) near "???????3???￥": syntax error
    >>> 
    


Answer: You are going to have an issue with these characters:

    
    
    ???????3???￥
    

It is unclear based on what you've posted where those are, but it's likely in
the file you're using to build your database from. The characters in that file
need to be in a character encoding that can be interpreted.

