ABP (. Net core 3.1 version) using MySQL database migration startup template project (1)


Recently, I want to build a new project, because I haven’t used. Net core, so I want to build a new project in the environment of. Net core. Because I am not familiar with the architecture of. Net core, I downloaded the ABP project to learn about it.
But I was too busy. I downloaded the template project, and I had many twists and turns in the process of starting. I can’t describe the twists and turns in words. (but I didn’t lose heart! There’s no skill that you can’t learn with effort, right
In the process of collecting information, the information shared by many netizens is very helpful, but there is a way to solve the problem that I encountered, because the problem has not been solved. But it gave me different ideas, so that the problem was solved, and the template project finally started smoothly.

First post my reference post, it is because there are excellent netizens to share, I opened the door of ABP template project! (I don’t want to talk about it. Long distance handshake, ha ha)

reference material

ABP tutorial (1) start template project

ABP (. Net core) uses MySQL database

According to the operation of reference materials, it only takes a few simple steps to start the template project, but! I don’t know why, if any new technology comes to me, it will take n steps, spend nine cattle and two tigers’ efforts, and rack my brains. It’s still a pile of red error reports. The screen full of red makes me depressed and makes me doubt my life

Let’s start with the steps.

  1. ABP template download

    ABP template download

  2. Open the project solution with vs2019 (vs2017 should be OK, but additional download. Net SDK 3.0 installation is required. )

  3. Find the [solution name Web.Host 】In the project appsettings.json , modify the database connection string
    Because my local SQL server did not connect successfully, there was no configuration tool, and I did not choose to install it again. Change the MySQL configuration. So my configuration is

    "ConnectionStrings": { "Default": "server=localhost;uid=root;pwd=123;port=3306;database=ExtraModuleDb;" }

  4. Add the installation reference with nuget in [solution name. Entityframeworkcore] (you can also refer to the second link above and execute with the command)

    install-package pomelo.entityframeworkcore.mysql.design

    install-package pomelo.entityframeworkcore.mysql

  5. Find the dbcontextconfigurer file in [solution name. Entityframeworkcore] and modify the database configuration connection


    `public static void Configure(DbContextOptionsBuilder builder, string connectionString)
     public static void Configure(DbContextOptionsBuilder builder, DbConnection connection)
  6. data migration

    It is better to delete the migration folder under solution name. Entityframeworkcore

    Then add the [solution name Web.Host 】Set as the startup project, and set the default project as entityframeworkcore in the package manager console (nuget console).

    Enter the command in the package manager console:Add-Migration Init

    If the generation is successful, you will see that there are three more files under the migration folder under the [solution name. Entityframeworkcore].

    Then update the database, ABP will automatically create the database. Enter the command in the package manager console:Update-Database -Verbose

    When I got here, the problem came. It was this problem that bothered me all morning.

    Familiar mistakes:You have an error in your SQL syntax

    It can be seen to the naked eye that datetime has a length. When creating tables in MySQL statements, datetime type does not allow length.

    Therefore, my approach is to manually replace datetime (6) with datetime in the code, and enter the command again in the package manager console:Update-Database -Verbose

    But the result is stillYou have an error in your SQL syntax。 Repeat operationAdd-Migration Init Update-Database -VerboseAfter, still can’t solve this problem, I have a little helpless, at the same time a little unwilling. I am an old bird. When I encounter unknown problems, the only way to solve them is to sit and sigh?!(definitely not!)

    I took a nap in the afternoon and went on to solve the problem. I have a look, why addpomelo.entityframeworkcore.mysqlWhat about citations? This manufacturer is not official oracle. Previous projects were not all added MySql.Data Is that right? With this doubt, I tried to changeMySql.DataWhen adding a reference, it is found that it has an entityframeworkcore version:MySql.Data.EntityFrameworkCoreSo we installed both. (be sure to install both, only installMySql.DataIt is incomplete. At least, there is no prompt when the database configuration link is wrong. I don’t know that it should be changed to usemysql.)

After installation, an error is reported during the operation. The MySQL in the original database configuration connection should be capitalized. (in fact, when I report an error, I wonder if it is mysql. Why not support it? I don’t know if it’s to change the upper case. When you put the mouse up and choose to repair it, it turns to uppercase and the error disappears.)

The compilation is successful! The official bag can also be used!

Then repeat the command in step 6:

Delete the files under the [migration] folder and execute the command in the package console:

Add-Migration Init

Update-Database -Verbose

okay! See the table successfully created in!

But, can’t be happy too early! Here comes the question!

The length of the string is too long. The last sentence prompts varchar max length = 65535. I don’t know how the code is generated, how to change the most basic code so as not to report low-level errors. Therefore, my solution here is to manually modify all the files under the migration folder that exceed the length of the data type. If the data type is not modified completely for the first time, it will be reported that it is wrong to change it once. After that, it is basically the problem that the length of data type exceeds. All changed, and thenUpdate-DatabaseFinally, the database is successfully created and the project is running.

Emmmm, the front-end one, is not familiar with this kind of separated project, vue.js I can’t run, I can’t see the whole picture of the whole project. This is the first part.