开发者

How to update data to gae localhost server from MySQL?

I follow this article to update data to gae localhost server from MySQL.

This is my str_loader.py is:

class College(db.Model):
    cid = db.StringProperty(required=True)
    name = db.StringProperty(required=True)

class MySQLLoader(bulkloader.Loader):
    def generate_records(self, filename):
        """Generates records from a MySQL database."""
        conn = MySQLdb.connect(host='localhost',user='root',passwd='root',db='test',charset="utf8")
        cursor = conn.cursor()
        sql ="select * from haha"
        cursor.execute(sql)
        #alldata = cursor.fetchall()
        return iter(cursor.fetchone, None)

class Mysql_update(bulkloader.Loader):
    def __init__(self):
        MySQLLoader.__init__(self,'College',
                                   [
                                    ('cid', str),
                                    ('name', lambda x: unicode(x, 'utf8')),
                                   ])
                                   ])

loaders = [Mysql_update]

And I use this code to run:

appcfg.py开发者_如何学JAVA upload_data --application=zjm1126 --config_file=upload/str_loader.py --filename=b.csv --kind=College --url=http://localhost:8100/remote_api

However, it shows an error.

So I change str_loader.py:

class Mysql_update(bulkloader.Loader):
    def __init__(self):
        MySQLLoader('College',
                                   [
                                    ('cid', str),
                                    ('name', lambda x: unicode(x, 'utf8')),
                                   ])

But it still shows an error.

What should I do?


Your Mysql_update class needs to subclass MySQLLoader, not bulkloader.Loader.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜