Hello again! Running into an error and have no idea why it’s happening
What I’m trying to do:
Trying to add a row to the database and it’s stating no column ‘description’ does not exist. I checked the table and the column is there.
anvil.tables.NoSuchColumnError: Row update failed: Column ‘description’ does not exist and automatic column creation is disabled.
Code Sample:
@anvil.server.callable
def add_item(item_dict):
app_tables.items.add_row(**item_dict)
@handle("add_item", "click")
def add_item_click(self, **event_args):
# new dict to store user input
fa_num = self.item['fa_num']
new_item = {'fa_num': fa_num}
# alert the opens AddItemComponent to add an item via popup
save_clicked = alert(
content=AddItem(item=new_item),
title="Add Item",
large=True,
buttons=[("Save", True), ("Cancel", False)],
)
# If the alert returned "True", the save button was clicked
if save_clicked:
anvil.server.call("add_case", new_item)
self.refresh_items(fa_num)
Also confirmed there are no spelling errors. Thanks in advance!
The first thing that jumps out to me is the @anvil.server.callable and the @handle("add_item", "click").
@anvil.server.callable is used to define functions on the server that can then be called from the client. @handle("add_item", "click") is used for event definition on the client
These shouldn’t reside in the same file. Perhaps you did this for brevity.
You show add_item but then you are calling add_case. Perhaps this is your issue.
I can’t see the details of your server function add_case so I can’t really help there. But, assuming that it is similar to your add_item function you have there, that should work fine.
I would open the server REPL and try manually calling your add_???? server function. Does it work if you omit the description key?
My guess is either there is a misspelling or you are targeting the wrong table.
Here is something that could help you do some debugging:
@anvil.server.callable
def add_subscription(subscription_data: dict):
table = app_tables.subscriptions
# For Debugging
# Here is a strict replacement of only good data
subscription_data = check_table_alignment(table, subscription_data)
# Here is quite check
check_table_alignment(table, subscription_data)
table.add_row(**subscription_data)
def check_table_alignment(table, data: dict) -> dict:
""" Check the given data for alignment with the table columns.
table: table to check data on
ie. table=app_tables.users
data: data you want to check aligns with table.
ie. {"name": "Arthur Dent"}
I'm not checking that datatypes match here...
"""
columns = {column['name']: column['type'] for column in table.list_columns()}
bad_data = {key: value for key, value in data.items() if key not in columns}
good_data = {key: value for key, value in data.items() if key in columns}
print("Good Data:")
print(good_data)
print("Bad Data:")
print(bad_data)
return good_data