{"id":661,"date":"2018-01-16T17:43:48","date_gmt":"2018-01-16T17:43:48","guid":{"rendered":"http:\/\/sezeromer.com\/?p=661"},"modified":"2018-03-02T11:01:12","modified_gmt":"2018-03-02T11:01:12","slug":"code-first-ile-veritabani-guncelleme","status":"publish","type":"post","link":"https:\/\/sezeromer.com\/en\/code-first-ile-veritabani-guncelleme\/","title":{"rendered":"Updating the Database with Code First"},"content":{"rendered":"<p>Updating the database with <strong>Code First<\/strong> is quite difficult. We need to use Migration for this. In our project we have created, we first open the <strong>Package Manager Console<\/strong>. Here we type <strong>Enable-Migrations<\/strong> and press the enter key. I said that because I enabled it earlier in this project. After you enable it, we will create a new folder named <strong>Migrations<\/strong>. Changes you make in this folder will be included.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-663\" src=\"http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/01\/migration-1.png\" sizes=\"(max-width: 382px) 100vw, 382px\" srcset=\"http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/01\/migration-1.png 382w, http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/01\/migration-1-300x53.png 300w\" alt=\"\" width=\"382\" height=\"68\" \/><\/p>\n<p>If you want to create a new table and add it to the database, you can do as follows. With <strong>Migrations<\/strong> you can update your data again without ever having to delete it again.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-664\" src=\"http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/01\/migration-2-1024x48.png\" sizes=\"(max-width: 1024px) 100vw, 1024px\" srcset=\"http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/01\/migration-2-1024x48.png 1024w, http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/01\/migration-2-300x14.png 300w, http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/01\/migration-2-768x36.png 768w\" alt=\"\" width=\"1024\" height=\"48\" \/><\/p>\n<p>After that, we need to enter the <strong>Package Manager Console<\/strong> again and enter the <strong>Update-Database<\/strong> command in order to save this change. When we enter we create a new table without deleting the data.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-665\" src=\"http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/01\/migration-3.png\" sizes=\"(max-width: 756px) 100vw, 756px\" srcset=\"http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/01\/migration-3.png 756w, http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/01\/migration-3-300x42.png 300w\" alt=\"\" width=\"756\" height=\"105\" \/><\/p>\n<p>If you want to delete a column in a table or add a new column, we need to enter the command &#8220;Add-Migration Add&#8221;. Of course, after this process we need to update the database again. We can do this with the Update-Database command.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-666\" src=\"http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/01\/migration-4-1024x46.png\" sizes=\"(max-width: 1024px) 100vw, 1024px\" srcset=\"http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/01\/migration-4-1024x46.png 1024w, http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/01\/migration-4-300x13.png 300w, http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/01\/migration-4-768x34.png 768w\" alt=\"\" width=\"1024\" height=\"46\" \/><\/p>","protected":false},"excerpt":{"rendered":"<p>Updating the database with Code First is quite difficult. We need to use Migration for this. In our project we have created, we first open the Package Manager Console. Here we type Enable-Migrations and press the enter key. I said that because I enabled it earlier in this project. After you enable it, we will [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":621,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[254,257,253,252,250,255,7,256,251],"class_list":["post-661","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-ile-ilgili-yazilar","tag-add","tag-code-first","tag-column","tag-databse","tag-migration","tag-nuget-package","tag-omer-sezer","tag-package-manager-console","tag-web-service"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts\/661"}],"collection":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/comments?post=661"}],"version-history":[{"count":3,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts\/661\/revisions"}],"predecessor-version":[{"id":1020,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts\/661\/revisions\/1020"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/media\/621"}],"wp:attachment":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/media?parent=661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/categories?post=661"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/tags?post=661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}