In today’s post, we will talk about setting up the database. While most developers prefer to work in a Code-First kind of an approach, I will using a Database-First approach for this project. The main reasoning behind this is that in almost all real world examples, someone else will be creating the database (or already has), for your application. While Code-First allows integrating with an existing database, the actual database-first route makes more sense to me.¬†

As mentioned earlier, we will be using MySQL for our database. MySQL provides a great tool in MySQL Workbench to design and maintain a database. I would say this is more powerful than using SQL Server Management Studio, at least for the database programming end of things. Plus it looks better! This post is not a tutorial for how to use MySQL Workbench. You can find many online articles on that.

Lets see how to sync your database changes to a database server:

First build your database using the modeling tool.


Click Database -> Synchronize Model to bring up the sync process.


Enter connection properties and click next to get the success screen.


Select the database in question. Workbench will ask you to create a new one if needed. Once selected, it will present elements available to sync.


In the next screen, the tool will generate the SQL for you to copy, or provide the ability to just go ahead and make the changes (an option I use a lot).

At this point, my database is all set with the schema changes I want. Now I create an init script, and insert the initial values I want to be setup before I start coding.

Hope this post helped you.