Discussion:
utf8 encoding issue in MySQL
KevinTran
2009-01-15 20:17:50 UTC
Permalink
I have the table definition below:

urls = Table('url', meta,
Column('id', Integer(11), primary_key=True),
Column('address', Unicode(1024)),
Column('content', Unicode(255)),
mysql_engine='InnoDB'
)

This will make the SQL below:

CREATE TABLE `url` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`address` varchar(1024) DEFAULT NULL,
`content` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
) ENGINE=InnoDB DEFAULT CHARSET=latin1

I want to know how I can specify the encoding for the table so that it
generates the following:

DEFAULT CHARSET=utf8

instead of DEFAULT CHARSET=latin1 as it is now.

As it is now, SQLAlchemy stores the table using the latin1 encoding
and converts the data back into Python unicode objects. This is fine
as long as I use only SQLAlchemy. The thing is that my code and the
table need to interact with other applications written by my colleague
and thus the tables must be encoded with utf8. I cannot find the
syntax to specify the encoding of the table.

Thanks and I hope that my question makes sense.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to ***@googlegroups.com
To unsubscribe from this group, send email to sqlalchemy+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---
Michael Bayer
2009-01-15 21:58:33 UTC
Permalink
I think this is configurable on the MySQL server directly, i.e.
default charset, otherwise you can set it via **{'mysql_DEFAULT
CHARSET':'utf8'} in your Table def.
Post by KevinTran
urls = Table('url', meta,
Column('id', Integer(11), primary_key=True),
Column('address', Unicode(1024)),
Column('content', Unicode(255)),
mysql_engine='InnoDB'
)
CREATE TABLE `url` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`address` varchar(1024) DEFAULT NULL,
`content` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
) ENGINE=InnoDB DEFAULT CHARSET=latin1
I want to know how I can specify the encoding for the table so that it
DEFAULT CHARSET=utf8
instead of DEFAULT CHARSET=latin1 as it is now.
As it is now, SQLAlchemy stores the table using the latin1 encoding
and converts the data back into Python unicode objects. This is fine
as long as I use only SQLAlchemy. The thing is that my code and the
table need to interact with other applications written by my colleague
and thus the tables must be encoded with utf8. I cannot find the
syntax to specify the encoding of the table.
Thanks and I hope that my question makes sense.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to ***@googlegroups.com
To unsubscribe from this group, send email to sqlalchemy+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---
KevinTran
2009-01-17 04:09:41 UTC
Permalink
Thanks you. It worked.
I think this is configurable on the MySQL server directly, i.e.  
default charset, otherwise you can set it via **{'mysql_DEFAULT  
CHARSET':'utf8'} in your Table def.
Post by KevinTran
urls = Table('url', meta,
   Column('id', Integer(11), primary_key=True),
   Column('address', Unicode(1024)),
   Column('content', Unicode(255)),
   mysql_engine='InnoDB'
)
CREATE TABLE `url` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `address` varchar(1024) DEFAULT NULL,
 `content` varchar(255) DEFAULT NULL,
 PRIMARY KEY (`id`),
) ENGINE=InnoDB DEFAULT CHARSET=latin1
I want to know how I can specify the encoding for the table so that it
DEFAULT CHARSET=utf8
instead of DEFAULT CHARSET=latin1 as it is now.
As it is now, SQLAlchemy stores the table using the latin1 encoding
and converts the data back into Python unicode objects.  This is fine
as long as I use only SQLAlchemy.  The thing is that my code and the
table need to interact with other applications written by my colleague
and thus the tables must be encoded with utf8.  I cannot find the
syntax to specify the encoding of the table.
Thanks and I hope that my question makes sense.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to ***@googlegroups.com
To unsubscribe from this group, send email to sqlalchemy+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Continue reading on narkive:
Loading...