Unconsumed column name when column actually exists and is correct case

See original GitHub issue
def update_sqalchemy_zone_config(table_name, zone_name, field_name, field_value):
    metadata = MetaData(bind=None)
    table = Table(table_name, metadata, autoload=True, autoload_with=engine)
    stmt = table.update().where(table.c.name == zone_name).values(field_name = field_value)  

update_sqlachemy_zone_config('zones', 'zone1', 'enabled', False)

results in:

sqlalchemy.exc.CompileError: Unconsumed column names: field_name

However, if I change field_name to enabled (my field name) it works: from: stmt = table.update().where(table.c.name == zone_name).values(field_name = field_value) to: stmt = table.update().where(table.c.name == zone_name).values(enabled = field_value)

MYSQL 8.0.19 Linux Ubuntu 18.04.3 LTS

There is only one table in my database and it is called zones and only one column in that table is called enabled.

print(table.c.keys()) ['name', 'zone_number', 'description', 'gpio', 'enabled']

from sqlalchemy.schema import CreateTable print(CreateTable(table).compile(engine)

CREATE TABLE zones (
    name VARCHAR(15) COLLATE utf8_unicode_ci NOT NULL, 
    zone_number TINYINT NOT NULL, 
    description VARCHAR(40) COLLATE utf8_unicode_ci NOT NULL, 
    gpio TINYINT(1) NOT NULL, 
    enabled TINYINT(1) NOT NULL, 
    PRIMARY KEY (zone_number)
)DEFAULT CHARSET=utf8 ENGINE=InnoDB COLLATE utf8_unicode_ci

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
CaselITcommented, Apr 10, 2020

A python method with this signature values(field_name = field_value) will pass a this dict: {'field_name': field_value}

You need to use values(**{field_name : field_value})

0reactions
CaselITcommented, Apr 10, 2020

You’re welcome. I’ll close this. Feel free to reopen it if you have other problems

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - CompileError when trying to run Insert Statement on ...
I figured this out by using SQLalchemy's inspector function. The column names were there, they were just in lower case. from sqlalchemy import ......
Read more >
What's New in SQLAlchemy 0.8?
The new operator system in Core adds the one hook that's been missing all along, which is to associate new and overridden operators...
Read more >
Error in rename of column names in R - RStudio Community
Hi, I tried doing it with backticks but it still doesn't work. ... Error in chr_as_locations() : ! Can't rename columns that don't...
Read more >
Cannot query Postgres database that has column names with ...
→ Drupal 8: Special content entity properties added via expressions are set with incorrect case such as $entity->isDefaultRevision , which ...
Read more >
13.1.18 CREATE TABLE Statement - MySQL :: Developer Zone
A PRIMARY KEY can be a multiple-column index. However, you cannot create a multiple-column index using the PRIMARY KEY key attribute in a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found