gpt4 book ai didi

mysql - Play framework 2.2.2 evolutions 未在 mysql 中触发

转载 作者:可可西里 更新时间:2023-11-01 07:14:55 30 4
gpt4 key购买 nike

在 play 文档中的示例待办事项应用程序中,使用 mysql 创建任务表并未创建演进。我尝试使用

applyEvolutions.default=true

在 application.conf 中。甚至尝试用

启动应用程序
start -DapplyEvolutions.default=true 

mysql 查询也不是问题,因为在 mysql 控制台中手动输入它可以正常工作。数据库连接也没有问题,因为在手动创建表后,插入和删除操作在应用程序中运行良好。

进一步引用这里的 application.conf

    # This is the main configuration file for the application.
# ~~~~~

# Secret key
# ~~~~~
# The secret key is used to secure cryptographics functions.
# If you deploy your application to several instances be sure to use the same key!
application.secret="PwleF1NyxkZ[8Oq`j`^NMg:6Vu6MMiHv?s:Ff>3@VpiKfA^9qSvb/E_>5[BRq>h6"

# The application languages
# ~~~~~
application.langs="en"

# Global object class
# ~~~~~
# Define the Global object class for this application.
# Default to Global in the root package.
# application.global=Global

# Router
# ~~~~~
# Define the Router object to use for this application.
# This router will be looked up first when the application is starting up,
# so make sure this is the entry point.
# Furthermore, it's assumed your route file is named properly.
# So for an application router like `my.application.Router`,
# you may need to define a router file `conf/my.application.routes`.
# Default to Routes in the root package (and conf/routes)
# application.router=my.application.Routes

# Database configuration
# ~~~~~
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
#
# db.default.driver=org.h2.Driver
# db.default.url="jdbc:h2:mem:play"
# db.default.user=sa
# db.default.password=""

# Evolutions
# ~~~~~
# You can disable evolutions if needed
# evolutionplugin=disabled
applyEvolutions.default=true

DapplyDownEvolutions.default=true

# Logger
# ~~~~~
# You can also configure logback (http://logback.qos.ch/),
# by providing an application-logger.xml file in the conf directory.

# Root logger:
logger.root=ERROR

# Logger used by the framework:
logger.play=INFO

# Logger provided to your application:
logger.application=DEBUG

db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/sql_test"
db.default.user="testuser"
db.default.pass=""

这里是 1.sql

# Tasks schema

# --- !Ups

CREATE TABLE task (
id int NOT NULL AUTO_INCREMENT,
label varchar(255),
PRIMARY KEY (ID)
);

# --- !Downs


DROP TABLE task;

最佳答案

检查以下内容:

您的进化文件(1.sql、2.sql 等)应该位于 conf/evolutions/default/目录中,其中 default 是您在 application.conf 中为数据库指定的名称。我的意思是

db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/sql_test"
db.default.user="testuser"
db.default.pass=""

接下来,检查您是否已在 application.conf 中设置自动应用上下演进,并且 evolutionplugin 已设置为启用

evolutionplugin=enabled
applyEvolutions.default=true
applyDownEvolutions.default=true

注意:你的 application.conf 中有 DapplyDownEvolutions

除了您的应用程序配置之外,还有一些其他事项需要检查:

  1. 您提供的登录凭据有效吗?
  2. 目标数据库中有表吗?我会确保从其中删除所有表格,包括 play_evolutions。
  3. 尝试使用“testuser”手动创建模式,也许登录名没有使用 CREATE 的权限

希望对您有所帮助。

关于mysql - Play framework 2.2.2 evolutions 未在 mysql 中触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22434007/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com