我正在进行代码优先,我需要删除第二次迁移,即基本上需要删除非迁移名称的最后一次迁移。
我用过 删除迁移 但它只删除上次添加的迁移。我尝试从解决方案中删除,但DBContextModelSnapshot.cs中剩下的代码很少。
是他们在EF Core中删除早期添加的迁移的更简洁方法。
由于
答案 0 :(得分:0)
重写历史记录很危险,但如果你知道自己在做什么,这是最好的方法。
import org.springframework.beans.factory.InitializingBean;
import org.springframework.http.HttpStatus;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.http.server.ServletServerHttpResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class UnauthorizedErrorAuthenticationEntryPoint implements AuthenticationEntryPoint, InitializingBean {
private HttpMessageConverter messageConverter;
@SuppressWarnings("unchecked")
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
MyGenericError error = new MyGenericError();
error.setDescription(exception.getMessage());
ServerHttpResponse outputMessage = new ServletServerHttpResponse(response);
outputMessage.setStatusCode(HttpStatus.UNAUTHORIZED);
messageConverter.write(error, null, outputMessage);
}
public void setMessageConverter(HttpMessageConverter messageConverter) {
this.messageConverter = messageConverter;
}
@Override
public void afterPropertiesSet() throws Exception {
if (messageConverter == null) {
throw new IllegalArgumentException("Property 'messageConverter' is required");
}
}
}
答案 1 :(得分:0)
我实际上更愿意删除上次和上次上次迁移,然后运行add-migration并检查迁移类中所做的更改,然后运行update-database。