I have a problem with migrating my database to a docker container.
During said migration I get the following error
System.InvalidOperationException: 'To change the IDENTITY property of a column, the column needs to be dropped and recreated.'
Docker-compose.yml:
version: '3.4'
networks:
backend:
services:
libraryapi:
container_name: Library-Api
image: ${DOCKER_REGISTRY-}libraryapi
build:
context: .
dockerfile: Dockerfile
networks:
- backend
ports:
- 8001:80
- 8003:443
environment:
- DB_HOST=librarydb
- DB_NAME=Library
- DB_SA_PASSWORD=q6ZOc32APBvTelKK6nlb0g31rVcWTq
librarydb:
container_name : Library-DB
image : mcr.microsoft.com/mssql/server:2022-latest
networks:
- backend
ports:
- 8002:1433
environment:
- ACCEPT_EULA=Y
- MSSQL_SA_PASSWORD=q6ZOc32APBvTelKK6nlb0g31rVcWTq
Dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY \["LibraryAPI.csproj", "."\]
RUN dotnet restore "./LibraryAPI.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "LibraryAPI.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "LibraryAPI.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT \["dotnet", "LibraryAPI.dll"\]
docker-compose-override (Whatever it is):
version: '3.4'
services:
libraryapi:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:443;http://+:80
ports:
- "80"
- "443"
volumes:
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
- ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro
I am starting my application via Docker Compose project in Visual Studio
I have already deleted the container, docker cache, and rebuilt the project multiple times. I have no more ideas what I can do.
1条答案
按热度按时间lndjwyie1#
I believe this problem is database-specific rather than Docker-related. Please take a look into the DB migration. It says you need to drop the column with identity property and recreate it to apply the migration. Your SQL code is wrong at the moment.