The operation failed because an index or statistics with name already exists on table EF6.1 - entity-framework-migrations

I used entityframework 6.0.2 and every thing work very nice,
but when i update entityframewrok to 6.1.1 application throw following exception :
The operation failed because an index or statistics with name already exists on table

After one hour i found solution
i used "Add-migration" when my Entity framework's version was 6.0.2 but migration structure is different in EF 6.1.1 ,
So , i delete migrations class and use "add migration" again.
every thing is ok now
Regards

Related

MVC 4 Server error

I am new to mvc in asp.net, so I have started with movie application in mvc with code first approach. My problem is when I change or add new field in movie class, then I got an error like
The model backing the 'MovieDBContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).
So anyone knows the solution for it with code first approach after changing or add any new field ...
using three command its solve which are list below.....which we have to write in package manager console
1)Enable-Migrations -ContextTypeName MvcMovie.Models.MovieDBContext
2)add-migration Initial
3)update-database
but why this error occurs and is there any other solution for it without the above three commands in mvc 4?
You have changed the Code First models since applying them to your database, so you need to reupdate, to apply these changes. First you add a new migration. Do this by typying this into the package manager console:
add-migration migrationName
migrationName should be unique and descriptive of the changes. After running this command, you should have a migration file, which you can apply by running:
update-database
Given that the changes are valid, they should now be applied to your database.
You have to do this every time you make changes to your CF models.

Entity framework manually deleted tables cant be generated from EF migration

I have created migration and created the database and the tables . For example the tables are
A B C D E . Now again I have changed some part of code and ran update-database command . Everything went smooth and nice and the tables showed the columns . Now accidentally I manually deleted one two tables D and E. Now when I try to run the migration with update-database . It runs properly but doesn't create the tables which I deleted manually . I tried to delete the existing migration and re-run update-database . It gives the error that apart from the two tables . There already an object existing in 'A ,B, C ' bla bla name.
Any idea how to get rid of this situation without dropping database and recreate the deleted tables using migration ? Cause i dont want to drop the database as it contains the data in rest of the tables. How to proceed in this situation where I have existing tables in database and accidentally I have manually deleted few tables from SQL server from SSMS .
How to recreate the tables again using migration ?
Oh my entity framework version is 6.0.2
EF Migration history is stored in the table _MigrationHistory. Remove the table from the Database. Caution: This will erase all the Migration history and you will have to re-create all the tables
I finally figured out the solution . Its basically change in strategy how we use migration . The Migration Add-migration only checks the Models and the previous migration timestamp cs files possibly . so until and unless we provide update-database command in nuget . it Never actually gets to know which Tables have got deleted manually . So to the context when we try to perform some migration like alter on the tables . It causes problematic migration since that table doesn't exist on the database but the migration assumes it is already there . So for that there is a manual work . Here are the steps after we have deleted a table manually from the database
Check the models existing in entities with correspondence to the database table . If we have found there are some anomaly in the database table which is missing from database but it exists as entity that means. They both are not in sync with each other. So we have to find the model => Table relation for each .
If we have created initial migration with all tables then copy the deleted createTable code from the migration file .
Paste it into the last recently generated migration file. And then generate the script or run the update-database command . That would create the deleted database table . However there is no automatic command which would both sync between all entities and the database tables . That's something which we have to track partially manual in migration.
you can do a simple trick here, remove the specific migration history rows, which affect your deleted tables from
dbo.__EFMigrationsHistory
then run update-database command,
enjoy
IMHO the most straightforward solution is to generate SQL script form the migration and run only a part of the script, that creates missing tables.
Update-Database -Source MigrationBeforeCreatingTables -Target MigrationAfterCreatingTables -Script
not best but possible way:
1)create a new migration, don't update the base
2)find migration that added tables you need
3)copy up and down parts from that old migration
4)past those things in the new migration file
5)update the database by the new migration

Deleted CRUD Table Facade.class still being generated: how to remove?

I removed a table from my Derby database, re-generated the 'Entity classes from database' and regenerated the CRUD files in Netbeans 7.0.1 but it keeps generating a Facade.class file for the deleted table: 'SEARCH_CRITERIA_TBL'.
I have deleted everything I can find related to the CRUD and done a clean and rebuild but it insists on regenerating the file:
\NetBeansProjects\Server\build\web\WEB-INF\classes\JSFBeans\SearchCriteriaTblFacade.class
The project compiles but the server fails to start with the following error:
Blockquote
WARNING: Exception while starting bundle com.sun.enterprise.osgi-adapter [154]
org.osgi.framework.BundleException: Activator start error in bundle com.sun.enterprise.osgi-adapter [154].
at org.apache.felix.framework.Felix.activateBundle(Felix.java:1751)
at org.apache.felix.framework.Felix.startBundle(Felix.java:1622)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:915)
at org.jvnet.hk2.osgimain.Main.start(Main.java:140)
at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:640)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:1700)
at org.apache.felix.framework.Felix.startBundle(Felix.java:1622)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1077)
at org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:264)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassFormatError: Absent Code attribute in method that
is not native or abstract in class file JSFBeans/SearchCriteriaTblFacade
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at org.glassfish.web.loader.WebappClassLoader.findClass(WebappClassLoader.java:920)
at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1430)
at com.sun.enterprise.deployment.annotation.impl.ModuleScanner.getElements(ModuleScanner.java:247)
at com.sun.enterprise.deployment.archivist.Archivist.processAnnotations(Archivist.java:541)
at com.sun.enterprise.deployment.archivist.Archivist.readAnnotations(Archivist.java:433)
at com.sun.enterprise.deployment.archivist.Archivist.readAnnotations(Archivist.java:420)
at com.sun.enterprise.deployment.archivist.Archivist.readRestDeploymentDescriptors(Archivist.java:396)
at com.sun.enterprise.deployment.archivist.Archivist.readDeploymentDescriptors(Archivist.java:373)
at com.sun.enterprise.deployment.archivist.Archivist.open(Archivist.java:238)
at com.sun.enterprise.deployment.archivist.Archivist.open(Archivist.java:247)
at com.sun.enterprise.deployment.archivist.Archivist.open(Archivist.java:208)
at com.sun.enterprise.deployment.archivist.ApplicationFactory.openArchive(ApplicationFactory.java:148)
at org.glassfish.javaee.core.deployment.DolProvider.load(DolProvider.java:162)
at org.glassfish.javaee.core.deployment.DolProvider.load(DolProvider.java:79)
at com.sun.enterprise.v3.server.ApplicationLifecycle.loadDeployer(ApplicationLifecycle.java:612)
at com.sun.enterprise.v3.server.ApplicationLifecycle.setupContainerInfos(ApplicationLifecycle.java:554)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:262)
at com.sun.enterprise.v3.server.ApplicationLoaderService.processApplication(ApplicationLoaderService.java:362)
at com.sun.enterprise.v3.server.ApplicationLoaderService.postConstruct(ApplicationLoaderService.java:185)
at com.sun.hk2.component.AbstractWombImpl.inject(AbstractWombImpl.java:174)
at com.sun.hk2.component.ConstructorWomb$1.run(ConstructorWomb.java:87)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.hk2.component.ConstructorWomb.initialize(ConstructorWomb.java:84)
at com.sun.hk2.component.AbstractWombImpl.get(AbstractWombImpl.java:77)
at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:58)
at com.sun.hk2.component.LazyInhabitant.get(LazyInhabitant.java:107)
at com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:60)
at com.sun.enterprise.v3.server.AppServerStartup.run(AppServerStartup.java:236)
at com.sun.enterprise.v3.server.AppServerStartup.start(AppServerStartup.java:128)
at com.sun.enterprise.module.bootstrap.Main.launch(Main.java:457)
at com.sun.enterprise.module.bootstrap.Main.launch(Main.java:401)
at org.jvnet.hk2.osgiadapter.HK2Main.start(HK2Main.java:125)
at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:640)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:1700)
... 9 more
Searches of the net only tell me what the 'JSF from Entity Classes' does not how it works internally. No doubt I am searching on the wrong terms...
Does anyone know where the Facade.classes create data is kept or can anyone tell me what terms I need to search on to find out? I have searched the entire project and found no reference to 'SearchCriteriaTbl' or 'SEARCH_CRITERIA_TBL'. I have manually deleted the SearchCriteriaTblFacade.class file, but it still reappears when the project is cleaned and rebuilt.
Kind thanks in advance.
Workaround: I re-inserted the deleted table into the database, regenerated the entity classes and CRUD files, and recompiled. Then removed the table again, re-created the entity classes from database and re-did CRUD creation. I then did a refactor delete rather than a normal delete of the unneeded files. After about three clean and recompiles it eventually sorted itself out and is now working.

Symfony doctrine migrations problem

I use symfony 1.4.11 , I have a project...
I have schema.yml , and I have migrations with tables which are not in the schema. For example I have in my db "pages" table, and it not described in schema. When I get project in first time I make: build --all --and-load --no-confirmation ; and I get my db,I think that it created some tables from Base classes, because there are many tables in my db, but they are not described in schema . So now I need add a few new fields to my page table, I make migration, and it is all ok, I have new fields in my db, but I do not have it in schema.yml, so when I make symfony doctrine:build --all-classes nothing happen it do not generate page class with new column. I do not understand, if it possible to generate new class or changes to class without schema? How people that make project before me , do this?
Thank you! And sorry for my bad English
it's possible. Try to use the following command to clean you model files.
./symfony doctrine:clean-model-files
if you want to use migrations, you should not use doctrine:build --all --and-load --no-confirmation anymore. Migrations assume incremental updates. Dropping and building the DB every time is not good.
Try to follow those resources
http://www.slideshare.net/weaverryan/the-art-of-doctrine-migrations
http://www.slideshare.net/denderello/symfony-live-2010-using-doctrine-migrations

How to avoid loading my models in a rails Migration

I have a rails project that uses an old versions of the FlexImage plug-in to handle images.
In the old version that image data was stored in a column called "data", in the new version that column must be named "image_file_data".
I wrote a migration to rename the column, but when I try to run the migration, my guess is that rails tries to load the models, which then automatically check to see if the valid column is there (which it isn't) and that throws an error which halts the migration.
I would guess that my problems would be solved if I never loaded the model classes in question and just wrote some sql to rename the columns. But the following line doesn't work, since rails still tries to load the model.
Apartment.connection.execute "ALTER TABLE logos CHANGE DATA image_file_data MEDIUMBLOB;"
Oops, I figured it out. I was calling
model = (table_name.to_s).classify.constantize
Earlier, and this was causing the model to load

Resources