[英]How to rename a sqlite column in python?
我得到此代碼來更改 python 中 sqLite 數據庫中的列名:
conn = sqlite3.connect('database.db')
cursor = conn.cursor()
cursor.execute('''ALTER TABLE products RENAME COLUMN buying_options TO shipping_options''',conn)
conn.commit()
與 output:
ValueError Traceback (most recent call last)
<ipython-input-131-1a4a76805a4c> in <module>
1 conn = sqlite3.connect('database.db')
2 cursor = conn.cursor()
----> 3 cursor.execute('''ALTER TABLE products RENAME COLUMN buying_options TO shipping_options''',conn)
4 conn.commit()
5 test_df = pd.read_sql_query('SELECT * FROM products',conn)
ValueError: parameters are of unsupported type
我的數據庫如下所示:
test_df = pd.read_sql_query('SELECT * FROM products',conn)
test_df.columns
給
Index(['product_id', 'seller', 'title', 'views', 'tags', 'nr_of_sales',
'origin_country', 'ships_to', 'category', 'link', 'description',
'payment_type', 'class', 'buying_options', 'listing_date',
'product_class', 'nr_of_options', 'nr_of_reviews', 'usd_price'],
dtype='object')
我不知道出了什么問題,語法應該是正確的吧? 我正在運行 sqlite 3.31
你應該嘗試改變
cursor.execute('''ALTER TABLE products RENAME COLUMN buying_options TO shipping_options''',conn)
至
cursor.execute('''ALTER TABLE products RENAME COLUMN buying_options TO shipping_options''')
您可以在此網站上找到更多信息: https://docs.python.org/3/library/sqlite3.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.