I have a db with 5 tables. At the beginning, I've added those tables in, but then decided to remove some due to some relationship compile error.
Now, when i want to add them back, i'm opening the edmx file -> update model from database... I don't see those tables under add tab, but only under the "refresh" tab.
How can i add them back?
In order to re-add a table to your model you will first need to delete the table from your model. (a list of tables is visible in the [model.Store] tree (see 'Model Browser' pane- you can open it from right-mouse click menu).
When you run 'Update model from database...' the table will appear in the 'Add' tab in the first step of the 'Update Wizard'.
Steps to complete:
Close your model in Visual
Studio.
Open your .edmx file in a
text editor.
Search and delete
the xml entity elements (see notes
below).
Open your model in Visual
Studio.
Click Update Model from
Database.
To delete all references to a table in your Model:
In the 'EntityContainer' element,
delete all 'EntitySet' child elements
that have the 'Name' attribute set to
the value [TableNameToReAdd].
In the
'EntityContainer' element, delete all
'AssociationSet' child elements where
an 'End' element exists that have
their 'EntitySet' attribute set to
the value [TableNameToReAdd].
In the
'EntityContainer' element, delete all
'EntityType' child elements where
that have the 'Name' attribute set to
the value [TableNameToReAdd].
In the
'EntityContainer' element, delete all
'Association' child elements where an
'End' element exists that have their
'Role' attribute set to the value
[TableNameToReAdd].
I reading this and other searching option, but finally I have found another answered which help me to short-out this issue.
From the error message looks like one of your table/view doesn't have
a primary key. EF needs every table to have a primary key in order to
generate Entity keys. You may still be able to run your application,
but I strongly suggest you add primary keys as warned.
Link which solved my issue.
Updated
If some time you done everything fine, still does not reflect the changes either adding a new column or change data-type.
The best way of this try to update manually, still there is no hope, then as suggested #mathijsuitmegen, delete and add the table, but this is last option to prefer.
An easier solution is in the Model Browser under
[modelName].Store -> Tables/ViewS
delete the table not showing up. Then right click on the model "update from database" and the table should be there.
You want to re-add an entity after it is deleted in the model.
Besides editing the edmx file there's another way to do this.
You will have to temporary delete the table from the database.
note: I would only to this if the database is not in production yet!
So in SQL Server Management Studio first create a script:
right click on the table(s) that correspond with the missing entity in your model. Select 'Script Table as', 'CREATE To', 'New Query Editor Window'.
The Second step is to delete the table. Right click again and select 'Delete'. Confirm the delete.
Back in Visual Studio do an update of the model.
Go back to SQL Server Management Studio and run the 'create' script you have just created.
The table will be added to your database again.
In Visual Studio you can now do an update again, your table will show up under the 'add ' tab!!!
In addition to the above list of references that need to be deleted from the model please consider removing AssociationSetMapping element as well in case if your table has associative relationship with other tables.
Related
I have one already existing Talend Open Studio tMySQLInput component with some sql code inside it, in order to retrieve some joined columns linked to a tMySQLOuput component (pointing to an already existing MySQL table) with few records.
QUESTION:
Will the "tMySQLInput" component overwrite the already existing table data that the tMySQLOutput component relates to? I mean is there an option to check in the tMySQLInput our output in order to say, overwrite each time this job is executed ?
Thank you all.
Yes, there is an option where in tMySQLOutput where you can specify what action you want to do to your table. Follow following steps:
Go to component tab of tMySQLOutput, it will open the basic settings of this component.
If you will look closer you will find Action on table. This is the action which you can perform on the table which is pointed by tMySQLOutput. It has options as Default, Drop and Create Table etc.
Then you have Action on data. These are the options which you can perform on the data like Insert, Update etc.
In your case I suppose you can choose Action on Table as Default and Action on Data as Insert. Default action would not do anything on the table and Insert option would insert the records at the end of table. But in case of Insert if you will have duplicate rows then job would stop the moment it will find any duplicate row.
We have a MySQL Workbench project with two tabs (two schemas/two databases).
If we create a table in the first tab, it's attached to the schema
magikweb_dev_igcweb.
If we create a table in the second tab, it's attached to the schema
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.
Use the model tab. You can cut out a table from one schema tab and insert it into another.
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:
File -> Export -> Forward Engineer SQL Script
Carefully edit SQL script. Replace references to one schema with the other, for the tables you want to move. Do this both for CREATE TABLE commands and foreign key references.
File -> New Model
File -> Import -> Reverse Engineer SQL Script
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.)
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.
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!
With a few solutions Ive worked with I've created temp table's or history tables. Normally I script it to take a handful of fields needed from a main table and copy it over to the other table by
Setting a variable then setting field to the variable for each field in the new table / new record.
I have a situation now, where Im building a history table that needs to copy the current record as is. A snapshot where all fields from that instance of the record are copied to the history table.
Rather then setting a variable then set field to the variable, Id like to get some input on a quicker way to get this done where I can do this on a record level and not type out field by field to get it done. Also if fields are added to both tables then I have to make sure my script gets updated.
Ill keep hunting around.. appreciate any help.
-Rich
Do you have a sample of copying a record from 1 table to another
including all fields and setting some fields?
As I suggested in comments, use the Import Records[] script step, and select the same file as the source. If you choose Arrange by: [ matching names ] in the Import Field Mapping dialog, it will automatically map all source fields to their similarly named counterparts.
Note that you must establish a found set in the source table before importing.
For "setting some fields", you can define auto-enter options and activate them during the import, or run Replace Field Contents[] immediately after the import.
i'm using Crystal Reports with my ERP-System. There have been predefined reports i now want to change.
In the field-explorer are some tables which have been renamed for better readability. But those tables are missing some fields, i want to use. If i connect the whole table again, all fields are there. Is there a way to display all fields in the predefined tables.
I tried to refresh the Database but nothing changes. If i delete the predefined table and then rename the new one to the old one, so i can use all predefinded formulas, all used fields in the report get deleted. I would need to recreate the whole report then.
Thanks for the help
If it is truly the same table and is not showing all the fields then you need to do "Database > Verify Database". That will force CR to refresh the structure of the table (instead of just the data). If this doesn't add the missing fields then the table in the report is actually a different object.
To see what the table/view the report is actually using go to "Database > Set DataSource Location" and look at the properties node for that table. It will show if it is a table/view/SP and what the true object name is.
If you want to replace the existing table with a different table you go to "Database > Set DataSource Location" again. Highlight the existing table in the top window, connect and highlight the replacement table in the bottom window. Then click update. Crystal will replace one table with the other and all of the fields in the report that exist in the new table will be mapped automatically. Note that the new table will keep the alias of the original table. If you are unsure if the table was updated you can look at the properties node in the top window to see the change.
Recently I started using MySQL Workbench to design my data structures with an UML diagram. However, there is one thing I could figure out.
It seems that if I delete a table from the EER-diagram view, the table persists in the catalog view (as illustrated by the screenshot below). I could find a way to delete from the catalog view and it still list in the foreign key table reference selection screen.
This is very confusing. How can I effectively remove the table (not only from the view but from the whole project?
Notice, the two question tables one of which I deleted in the view and redesigned.
In case if the right-click and delete didn't work,
Simply drag and drop the table from the Catalog Tree to the Design area. Then you will see the table gets inserted there. From there, right-click on the table and select delete table. Then the table will get deleted from the whole project (assuming correspondent objects which are needed deleting as well).
Just had this problem before.
CMD + Backspace / delete on the keyboard will only delete the figure in the designer.
To completely delete the table and figure, instead try: Right-click > Delete 'table'.
I am using "MySQL Workbench Community (GPL) for Mac OS X version 6.2.3 revision 12313 build 2282 (32 bit)" and the action "delete 'table'" in the context menu (right-click on the table) did not work for me.
Believe it or not I had to restart the whole application. After the restart the delete action worked as expected. (1 object(s) deleted) [nothing about the object is kept in the DB]
This is how I discovered the difference between "delete" and "remove figure".
The "delete" deletes tables from the whole project, the "remove figure" only from the diagram (the tables still stay in the catalog).