Rename underlying table

Hi everyone,
I would like to to rename the underlying table in database which is conntected do metabase. But is there a way how to do it without destroying Questions?

I can imagine that it could as simple as renaming table name in metabase database in table metabase_table, but frontend still expect old table.

I don’t change the structure of the table, I just need to change the name. I don’t want to have the view with old name.

Thanks for an advice!

Hi @jhettler

Make sure you have backups before touching the application database, since it’s easy to end up in a corrupted state.

So do you need to just rename the table visually or is it renamed in your data source?

If visually, then just change the name in Metabase > Admin > Data Model.

If “physically” renamed, then yes, change the name in your data source and the application database table metabase_table while Metabase is shutdown, and then start Metabase again.
Note that it will not do anything to SQL questions - you would need to manually change the query there (or in table report_card)

Hi @flamber,

thanks for the reply! It was physically renamed in database, the second option is my case. Please, what’s the “magic” in renaming table while shutting down? Can I just simply switch metabase off and then rename it in metabase_table in database and then switch it on again?

@jhettler Yes. Otherwise Metabase doesn’t know the table has been changed, since it keeps a state in-memory to avoid constantly reading the application database.

An alternative approach is to shut down Metabase, rename the table, then create a view on the newly named table. The view needs to have the same name as the table previously had and be in the same schema.
That way, there’s no need to do anything to Metabase and your native queries will still work.

1 Like