Issue with Database views in Entity Framework - mysql

I am working on a web application using entity framework and MySql. I have created some views and tables in my database but unfortunately ADO.Net data modal is not including the views. I have recreated my data modal but still views are missing. I have applied several solutions which i have found on different forums some one was suggesting to restart visual studio, Even some people was asking to restart the PC. but its not working for me.

Finally i have managed to solve this problem by adding a primary key column in my select statement.It was obvious that we must need a primary key to add our table in modal but as views have no primary key that's why i was confused. In short we must have to include at least one primary key column of a table in select statement.

Related

Phpmyadmin version 4: Relation view sometimes does not show foreign key constraints

I have a database that I built a while back. Every table in the database is InnoDb. Several tables had foreign key constraints, and I set them up for On Delete = Cascade. When I was using an earlier version of phpmyadmin, working with these was simple: I'd just go to the Structure tab of a table, click the Relation View link, and as long as I had the correct indexes set up on the correct columns, I could set the foreign keys as I saw fit.
Since upgrading to version 4, it's become a nightmare. For some tables, I go to the relation view and everything is just fine. But for others--even when they already have foreign key constraints set--I can't see any options for working with them.
To make matters worse, I've even tried dropping the indexes and re-adding them, only to be given the following error: Cannot drop index [index_name]: needed in a foreign key constraint. So unless I'm mistaken, the constraint is there, but phpmyadmin is refusing to show it to me.
Is there something I have to do to make them show up again? This is extremely frustrating to say the least: something that worked just fine before now does not thanks to an upgrade.
OK, after playing around with the tables a bit, I figured out what's going on. The only time the foreign key constraint options don't show up are when the table names contain capital letters. Very frustrating to say the least.
I just filed a bug report for phpmyadmin: https://github.com/phpmyadmin/phpmyadmin/issues/11461
It should be an easy fix.
happened to me because i used '&" in the database name.
In my case it is that I used two columns (A and B) both as foreigns keys to other tables then I also used a composite unique for ([A, B]), phpMyAdmin does not show the existed foreign index of column A but does show that for column B.
My system version are as follows:
Server version: 5.7.30 - MySQL Community Server (GPL)

Grails Database Migration Plugin Issues

When I use the Grails Database Migration Plugin and run a dbm-gorm-diff (for example, after installing the Spring Security Facebook plugin) I have been getting problems like:
Error: Error executing SQL CREATE INDEX `FK609FD5A460CFCC39` ON `facebook_user`(`user_id`): Incorrect index name 'FK609FD5A460CFCC39'
It looks like the index in question is both a FK constraint and is then reused as an index later in the generated upgrade script. If i change the name, thus removing the duplicate, everything works fine. I am using Mysql. Am I doing something wrong?
Thanks.
I just found out that if I edit changelog.groovy to place addForeignConstraint's after createIndex's, it works like a charm. Yet another problem in the changelog generation script I guess.
I suspect this is actually related to MySQL and not to the plugin itself. See this bug: http://bugs.mysql.com/bug.php?id=55465
Sebastien's answer is a work around.
As per this question/answer, MYSQL automatically indexes foreign key columns. So when you add a foreign key constraint, you don't need to also define an index. I use the db migration plugin and just remove the 'index' entries for foreign keys that the dbm-gorm-diff generates.
I think this is a bit better than changing the name, since that likely creates more than one index on the same column which is just a waste of resources.

Play framework - database create-drop issue

I'm working with Play! 1.2.4 and I've come across a curious issue.
As far as I'm aware if I set the jpa.ddl in my configuration to create-drop it should drop my tables and rebuild and application restart.
jpa.ddl=create-drop
Am I right in thinking that it will only drop and create tables associated with models that have changed? I'm getting a problem where I have a model which has changed, but it isn't dropping the table. I tried to drop the table manually but it won't allow it because it Cannot delete or update a parent row: a foreign key constraint fails. I understand this problem and to fix it I could manually drop my entire table and restart my application so it builds the tables from scratch.
My question is, is this the problem that Play! is having which is why it isn't updating that table, and if so is there a way to get around it through configuration files rather than manually dropping my table?
Thanks.
EDIT
Just for some more information, I am just assuming this is a problem and it might be something completely different but here is what I get in my logs:
Unsuccessful: create table Product
Table 'Product' already exists
I also just realised a change occuring on this load. I used to have a relationship like so
Product *-* Image
That being a ManyToMany relationship between the Product and Image table. The Image table is now not there and the relationship will be gone. However, it looks to me like the Image table isn't being deleted but the Product one is trying to be deleted and rebuilt. This might be causing the issue wit the foreign key constraint. Why wouldn't Play delete that table if its Model doesn't exist anymore?
Runing play in dev mode?
But why don't you use jpa.ddl=update?
Automatic schema modification with jpa is not really the best way to do. Play provides the evolutions mechanism which is more reliable because you indicate what are the changes.
In the example you give, if you delete a model class like Image, JPA does not know anything about Image class anymore so it won't delete the Image table and the Product_Image relationshop table. Thus it can't delete the Product table. JPA do not have any knowledge on what was the database before you change your model.
Evolutions are a bit more tedious to do use at start because you create evolutions files by hand but with this mechanism, your database structure is exactly what you want

Do i need to make sql tables using constraint to work with hibernate

I am using hibernate annotations with spring MVC.
Now i always create table using GUI editor like SQLYOG or phpmyadmin.
So i just create table with columns and even if i have some tables primaray key in other table , i just make that column with name like
Person ---id--name--age
SUbject------person_id----description
So i made those tables using GUI with mentioning anything about foreign key etc.
There is option in GUI editor ti make it primary kay and Auto increment so it usually works till now.
But i want to know that in Hibernate do i need to make tables with proper sql command . i mean do i need to mention which table is primary key and which is foreign key
or hibernate annotations are enough for that
Hibernate will work just fine as long as your annotations are correct.
But from a database design point of view I strongly suggest that you create at least the primary key and foreign key constraints.
Your queries will run much faster if you create the primary keys. You can improve performance a little more by creating other kinds of indexes to.
PHPMyAdmin is perfectly able to create primary keys for you, as well as every other index types there is in mysql. There's no need to write your creation code by hand.

...is not a foreign key column and cannot be used here?

I have two views in SQL, and have created mappings to them in Linq to SQL.
The two views have an association, which works fine, between Ticket.ProblemCode and Problem.Code
When I try to set UIHint("ForeignKey") on Ticket.ProblemCode and run the web page I get the error:
'ProblemCode' is not a foreign key column and cannot be used here.
Anyone know why? More importantly, how to fix it?
See this post on the ASP.NET forums:
http://forums.asp.net/t/1254559.aspx
Also, you said that you created the association in Linq to SQL. Is there an actual PK/FK constraint in the database, or is it only represented in your dbml?