EFMigration.md 2.2 KB
Newer Older
1
2
3
4
5
6
7
# Create the migration of database:

```
Add-Migration Initial -context AdminDbContext -output Data/Migrations
Update-Database -context AdminDbContext
```

8
9
10
11
12
13
14
15
# Using other database engines


## PostgreSQL

Install following NuGet package:

```
Michał Drzał's avatar
Michał Drzał committed
16
Npgsql.EntityFrameworkCore.PostgreSQL
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Npgsql.EntityFrameworkCore.PostgreSQL.Design
```

Find `RegisterDbContexts` function in `Helpers\StartupHelpers.cs`

```csharp
services.AddDbContext<AdminDbContext>(options => options.UseSqlServer(configuration.GetConnectionString(ConfigurationConsts.AdminConnectionStringKey), optionsSql => optionsSql.MigrationsAssembly(migrationsAssembly)));
```

and change  `UseSqlServer` to `UseNpgsql`.

**Don't forget to update your connection string in appsettings.json and (re)generate migrations for new database**


## SQLite


Install following NuGet package:

```
Michał Drzał's avatar
Michał Drzał committed
37
Microsoft.EntityFrameworkCore.Sqlite
38
39
40
41
42
43
44
45
46
47
48
49
50
Microsoft.EntityFrameworkCore.Sqlite.Design
```

Find `RegisterDbContexts` function in `Helpers\StartupHelpers.cs`

```csharp
services.AddDbContext<AdminDbContext>(options => options.UseSqlServer(configuration.GetConnectionString(ConfigurationConsts.AdminConnectionStringKey), optionsSql => optionsSql.MigrationsAssembly(migrationsAssembly)));
```

and change  `UseSqlServer` to `UseSqlite`.

**Don't forget to update your connection string in appsettings.json and (re)generate migrations for new database**

51
52
53
54
55
56
## MySQL and MariaDB


Install the following NuGet package:
```
Pomelo.EntityFrameworkCore.MySql
Michał Drzał's avatar
Michał Drzał committed
57
Pomelo.EntityFrameworkCore.MySql.Design
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
```

Find `RegisterDbContexts` function in `Helpers\StartupHelpers.cs`

```csharp
services.AddDbContext<AdminDbContext>(options => options.UseSqlServer(configuration.GetConnectionString(ConfigurationConsts.AdminConnectionStringKey), optionsSql => optionsSql.MigrationsAssembly(migrationsAssembly)));
```

and change  `UseSqlServer` to `UseMySql`.

Find `Properties` in `Skoruba.IdentityServer4.Admin.EntityFramework\Entities\Log.cs`

```csharp
[Column(TypeName = "xml")]
public string Properties { get; set; }
```

and remove the `[Column]` attribute. As MySQL and MariaDB don't know about a XML data type.

**Don't forget to update your connection string in appsettings.json and (re)generate migrations for new database**