Major Problem When I Update Column Names in MySQL database

Hello!

Each time that I make a change to my database column names, everything that is related to queries for that table explodes. Tables stop loading, I get several javascript errors (not a primary expression, unexpected token in position ‘o’).

What is the right process for refreshing the database information on Wappler, so that I can prevent this? I have literally been stuck for hours trying to reproduce a table that I had working perfectly before. Now, all that I get is the headers of the table and 3 blank rows beneath it.

I have deleted the queries and recreated them.
I have deleted the server connections and recreated them.
I have deleted the tables and recreated them.
I have tried making a new page and trying the query on that. No success.

It seems like wappler saves some sort of information about the field names and cannot accept the change.

Can anyone help? I don’t want to have restart my entire project, but that kind of seems lile the logical next step.

You should not make changes to DB schema while actively developing an application using that DB.

To refresh the DB schema in Wappler, open any server action, or create new… and go to Connect DB step. Select the existing connection and Connection Settings to open DB details popup.
Click save. Everytime you click save on this, Wappler will re-save the DB schema.

When there is a change in the schema and fields are not recognized in existing server actions, they mostly become unusable from the UI. Click the Open in Editor button to view the JSON of server action.
There you can try to rename the column names, save the file, refresh server action panel, and see if the UI starts working again.

But, most importantly, avoid making any changes to existing column or table name or their data types. Adding new columns and tables is all good. But if you will make any changes in parts which are in use, things will break.

2 Likes

That is a huge restriction for a visual coder meant for rapid changes. Perhaps next time I need to make a change, I just add a new column instead of editing an old one. But that does not get me out of my current predicament.

Well, Wappler’s visual tools do not support DB creation or manipulation. They are just meant to consume it.
I do hope that handling such errors in Server Action get better in the future.

For you current project you can edit column name in editor to make it all work.

But, again, this is not a good approach towards developing database driven apps. Database design should be set in place before other layers of the app are designed.

Hello Marina,
You can easily “refresh” the database table column names in the query builder without deleting everything. Just click the refresh database schema button, so the new name can be synchronized:

However, there is no magic way to change it automatically on the page, if you used it there … you shoud go and pick the new data from the dynamic data picker dialog.

I do agree with what @sid says. It’s not the greatest idea to change database table column names, after you have used them already on your pages.
Better spend more time designing the logic and names, than changing them multiple times later.

Refreshing the schema is easy enough as Teodor says HOWEVER if you have a query which specifically refers to a field name which you have renamed or deleted then the query will break and it will not open. The only resolution if you have broken the query is to either edit the json schema or delete and recreate. I recommend you duplicate fields initially, remake changed references first then only when all references are changed delete the original. This has been discussed in a few previous threads, @patrick is aware and allowing “broken” queries to open so that can be edited is, I believe, on his to do list.

@Teodor is there anything Wappler can do to prevent this from happening? Somehow giving the user the ability to still edit/open the query builder after the database was changed.

I don’t think that should happen.
@patrick will take a look at this.

1 Like

There is indeed a problem when the column was used inside a where condition, I’m still trying to fix that, but seems to be more difficult then I first thought. A workaround is to first remove the old column from the where condition before refreshing the schema and then add it again with the new column. If the old column was not removed, it will stay there in the options, but it is not visible in the query builder, you then have to edit the generated json config for the action step directly in code.

5 Likes

Patrick is spot on!