Reputation: 4316
We have a MySQL Workbench project with two tabs (two schemas/two databases).
magikweb_dev_igcweb
.magikweb_dev_igcweb_archive
.If we copy-paste/duplicate a table from the first tab to the second tab, the resulting table remains in the first schema. How can you change a table's schema?
Each schema is linked with a specific database, so when we use the "Synchronize Model..." feature, it links all the tables properly.
Upvotes: 13
Views: 15716
Reputation: 1948
I found a less painful way to do this.
Save and backup your diagram and your schema.
Display schema's name before table's names in diagram. This will make the next step easier.
Right-click on the tables which are on the wrong schema, and select "Copy SQL to clipboard". Paste the script in a new SQL window. Repeat for each table you want to migrate.
Edit the script to change the schema name. Watch for any miss in entries, the wrong schema might be a reference at any line. Mine was mydb
, which I don't remember creating. Execute the script. Now you have the tables on the right schema.
Synchronize your model. Be sure to check "Update the model" for each missing table, otherwise, the tables will be deleted from the schema :)
Drag'n'drop the newly created tables into the diagram. Then remove the ones which are using the wrong schema. Tip: tables that are not in diagram won't display a dot next to their name.
Optionally, you can delete the faulty schema from the model so this never happens again. Be sure to know what you're doing first!
Upvotes: 0
Reputation: 722
Follow this simple steps (never miss step 4 and 5) :
Open Model Tab
Choose source schema. In my case, I want to copy table users
from schema abc_develop_v1
to schema abc_develop_v2
then paste to diagram . So I choose schema abc_develop_v1
, right-click table users
then Copy 'users'
Go to the targeted schema. In my case is schema abc_develop_v2
, right-click then Paste 'users'
Next, copy table users
from schema abc_develop_v2
. Right-click table users
then Copy 'users'
Go to your diagram and Paste 'users'.
That's all. Your table is ready in your diagram with the right schema
:-)
Notes: You can double check by double-click on the table in your diagram, and look at the right corner. It will show the
Schema
name.
Upvotes: 2
Reputation: 2220
The cut-and-paste method described in another answer works well for tables with no foreign keys, and for a reasonable number of tables.
An alternative that preserves foreign keys is to export the model as a SQL script, edit it, and then import the new script into a new model.
Using MySQL Workbench v6.3:
Unfortunately you will then need to recreate any diagrams. But that can be straightforward if you have the original diagram as reference (take a screenshot or export it to PNG or PDF.)
Upvotes: 7
Reputation: 53337
Use the model tab. You can cut out a table from one schema tab and insert it into another.
Upvotes: 8