CREATE TABLE IF NOT EXISTS `test_tab` ( `system_id` int(5) NOT NULL AUTO_INCREMENT, `id` int(4) NOT NULL, `name` char(255) DEFAULT NULL, `filtered_name` char(255) DEFAULT NULL, `real` enum('false','true') DEFAULT NULL, `image` char(255) DEFAULT NULL, PRIMARY KEY (`system_id`), UNIQUE KEY `id` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
При добавлении строки таким макаром:
# 2.7 # -*- coding: utf-8 -*- from mysql.connector import MySQLConnection, Error data_in_db = {'id': '2', 'name': 'test-test-test', 'filtered_name': 'test', 'real': 'true', 'image': '/images/2.jpg'} query = "INSERT INTO test_tab(id, name, filtered_name, real, image) " \ "VALUES(%d, %s, %s, %s, %s)" args = (data_in_db.get('id'), data_in_db.get('name'), data_in_db.get('filtered_name'), data_in_db.get('real'), data_in_db.get('image')) db_config = {'password': 'root', 'host': 'localhost', 'user': 'root', 'database': 'anime'} try: conn = MySQLConnection(**db_config) cursor = conn.cursor() cursor.execute(query, args) if cursor.lastrowid: print('last insert id', cursor.lastrowid) else: print('last insert id not found') conn.commit() except Error as error: print(error) finally: cursor.close() conn.close()
Что я делаю не так?
Делаю по вот этому примеру: http://www.internet-technologies.ru/articles/article_2190.html
но там не указана структура таблицы