Update partial database from entity Migration - aspnet mvc - sql-server

I have deleted and modified somes tables in database sqlserver manually, then I have deleted __MigrationHistory table...
Now, when i run "add-migration" command, it regenare commands for recreate entire structure of database, but I want to syncronize the structure from the model to database, without recreates all tables in database...
the comnand "add-migration -ignoreChanges" is not correct, because the
model of website is different from database, because i have manual
modified somes tables.....
is possibles?
thanks

Related

Symfony existing table error when updating database

I have the database entities in my Symfony application, I have created another table in the database and I want to download it as an entity in my program. When I execute the following line I get that there are tables that already exist.
php bin/console make:migration
How can I update the entities and create only the ones that are not there?

laravel change table in PHPMYADMIN without migration

I have several tables that I have created through migration. Then, what happens if I change the table structure directly from PHPMYADMIN without using migration? What if my backend team pulls my project, then runs the "php artisan migrate" command. Is the database on my backend team the same as the database that I have?
If you make changes through phpMyAdmin, these will only be visible to you. You should change the migrations, or if you can't change the original because you don't want to reset the database, you should create a new migration to alter the table. Check the documentation for altering tables here: https://laravel.com/docs/5.7/migrations#modifying-columns

Clone a database schema without any data

I need our end-users to "clone" a database from our web application UI. I am able to "clone" a database by backing up a source database and restoring it into a new database. In this way, I "clone" the table schema and data.
My question is - is there any way I can "clone" just the table schema, without the data? I am aware that we can script the database manually, and run that script. But our table schema changes frequently (we add new columns and tables regularly) and we wouldn't want to update this script. Thank you.
basically you have to:
save the datatase
restore the backup to a new database (use the with move option)
connect to the new database and then exec sys.sp_MSforeachtable 'truncate table ?'
PS: you may have to disable FK constraints if any.
Antother solution: use Entity Framework Database First to build a small program. Launch said program with a connection string pointing to a new db.
Right Click over database -> Tasks -> Generate Script
On Set Scripting Options page click Advanced
General -> Types of data to script = Schema Only
With SQL Server data tools you can generate the schema difference and apply only the changes to target database.

Is it possible to move the __MigrationHistory System table to a new server?

We recently moved our database to a new server. However, at the time, we did not allow the Code First migrations to create the database. We used another tool to migrate the tables and data. The __MigrationHistory table was not moved during this time. The __MigrationHistory is a system table in our original DB.
I cannot seem to find a way to import or export the __MigrationHistory table so we can allow future migrations to take place.
The only other thought we had, is to have the application recreate the database and migrate the copied data to the new version of the DB. The only issue is we have millions of records to move and it is quite a long process.
I use the following script to move the EF MigrationHistory table from the system tables to the user tables (of a database tree structure):
SELECT * INTO [dbo].[TempMigrationHistory] FROM [dbo].[__MigrationHistory];
DROP TABLE [dbo].[__MigrationHistory];
EXEC sp_rename 'TempMigrationHistory', '__MigrationHistory';
This way I can export the table by choosing standard script/export option under SSMS.
(The complete description of handling this issue is here)

On creating new database in sql server 2008, some tables created automatically?

When I create any new database It automatically create some tables in new database.
Details:
I created a new database "TestDatabase" using below command
Create database TestDatabase
When I expand the Tables folder, I found that there are already some tables created automatically.
These are those tables which I was using in some other database.
Table names:
1. Employee
2. Admin
etc
How can I create new fresh database to make sure that no tables created in it?
Presumably at some point you accidentally created these tables in the model database.
This is used as the template for creating new databases. Simply delete them from model to stop them appearing in every freshly created database.
SQL Server uses the model database as the basis for new databases. Check and see if these tables exist in model - and if they do, delete them.
You should probably check for other objects in modeltoo (stored procedures, views etc).

Resources