
The model backing the context has changed since the database was created
31 มกราคม 2557 | MVC
ERROR The model backing the ‘YourDbContext’ context has changed since the database was created. Consider using Code First Migrations to update the database หากเกิด error นี้คือ เรายังไม่ได้ตั้งค่าเริ่มต้นให้กับ database context หรือ database context ไม่สามารถเชื่อมไปยังฐานข้อมูลเพื่อดึงข้อมูลออกมาได้ ดังนั้นเราจึงต้องกำหนดค่าเริ่มต้นเพื่อเชื่อมไปยังฐานข้อมูลดังนี้ เพิ่มโค้ด Database.SetInitializer<ชื่อ DB Context>(null); เช่น Database.SetInitializer<EmployeeContext>(null); ลงไปใน Application_Start() ซึ่งอยู่ในไฟล์ Global.asax ตัวอย่าง