Doctrine CLI 的设置不太有效

发布于 2024-10-19 19:15:29 字数 2502 浏览 1 评论 0原文

仍在努力让学说在我的系统上正常工作。我有一个 yaml 文件,它描述了我的数据库和表的结构。 (我正在关注 zendcast 上的教程)。我有我的学说脚本文件,并且

#!/usr/bin/env php
<?php
chdir(dirname(__FILE__));
include('doctrine.php');

doctrine.php文件包含

<?php

// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/..'));

// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') :       'development'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));

/** Zend_Application */
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);

$application->getBootstrap()->bootstrap('doctrine');
$config = $application->getOption('doctrine');

$cli = new Doctrine_Cli($config);
$cli->run($_SERVER['argv']);

我的application.ini摘录是

autoloaderNamespaces[] = "Doctrine_"

;--
;Database
;--
doctrine.dsn = "mysql://root:softna@localhost/gepm2"
doctrine.data_fixtures_path = APPLICATION_PATH "/configs/data/fixtures"
doctrine.sql_path           = APPLICATION_PATH "/configs/data/sql"
doctrine.migrations_path    = APPLICATION_PATH "/configs/migrations"
doctrine.yaml_schema_path   = APPLICATION_PATH "/configs/schema.yml"
doctrine.models_path        = APPLICATION_PATH "/../library/Gepm/Model"

当我运行时:

D:\www\gepm2\application\scripts>php doctrine build-all-reload

我得到ff反馈:

D:\www\gepm2\application\scripts>php doctrine build-all-reload
build-all-reload - Are you sure you wish to drop your databases? (y/n) y
build-all-reload - Successfully dropped database for connection named 'doctrine'
build-all-reload - Successfully created database for connection named 'doctrine'
build-all-reload - Created tables successfully
build-all-reload - Data was successfully loaded

但是,当我检查mysql时,仅创建数据库,没有生成表。我为此奋斗了一整天。有人帮忙。


编辑


好吧,我现在可以使用了。但说实话,我对代码所做的唯一更改是 1.设置时区,
2. 删除 utoloaderNamespaces[] 值末尾的下划线,使 utoloaderNamespaces[] = "Doctrine_" 变为 autoloaderNamespaces[] = "Doctrine" 并且 ] 部分的底部

3. 将学说数据库声明移动到 applications.ini 中 [生产 。等我有空的时候我会说。与此同时,知识渊博的极客也许能够解释为什么它会起作用。干杯。

Still struggling to get doctrine working properly on my system. I have a yaml file that describes the structure of my database and tables. (I am following the tutorial on zendcast). I have my doctrine script file as

#!/usr/bin/env php
<?php
chdir(dirname(__FILE__));
include('doctrine.php');

and the doctrine.php file contains

<?php

// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/..'));

// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') :       'development'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));

/** Zend_Application */
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);

$application->getBootstrap()->bootstrap('doctrine');
$config = $application->getOption('doctrine');

$cli = new Doctrine_Cli($config);
$cli->run($_SERVER['argv']);

My application.ini excerpt is

autoloaderNamespaces[] = "Doctrine_"

;--
;Database
;--
doctrine.dsn = "mysql://root:softna@localhost/gepm2"
doctrine.data_fixtures_path = APPLICATION_PATH "/configs/data/fixtures"
doctrine.sql_path           = APPLICATION_PATH "/configs/data/sql"
doctrine.migrations_path    = APPLICATION_PATH "/configs/migrations"
doctrine.yaml_schema_path   = APPLICATION_PATH "/configs/schema.yml"
doctrine.models_path        = APPLICATION_PATH "/../library/Gepm/Model"

When I run:

D:\www\gepm2\application\scripts>php doctrine build-all-reload

I get the ff feedback:

D:\www\gepm2\application\scripts>php doctrine build-all-reload
build-all-reload - Are you sure you wish to drop your databases? (y/n) y
build-all-reload - Successfully dropped database for connection named 'doctrine'
build-all-reload - Successfully created database for connection named 'doctrine'
build-all-reload - Created tables successfully
build-all-reload - Data was successfully loaded

However when I check mysql only the database is created no tables are generated. I have struggled with this for a whole day. Someone help.


EDIT


All right I got it working now.But to be honest with you the only changes I made to the code was to
1. set the time zone,
2. remove the underscore from the end of the utoloaderNamespaces[] value so utoloaderNamespaces[] = "Doctrine_" became autoloaderNamespaces[] = "Doctrine" and
3. move the doctrine database declarations to the bottom of the [production] section in the applications.ini

I am so far behind on schedule with what I am working on that I cannot mess about with these changes to see which one or why it worked. I will do say later when I have some down time. In the meantime a more knowledgeable geek may be able to explain why it may have worked. cheers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

马蹄踏│碎落叶 2024-10-26 19:15:29

学说在数据库中创建表的方式是加载模型并读取每个模型中的定义。如果 CLI 无法加载模型,则表创建将失败。不幸的是 CLI 任务不会报告这一点。

此外,我建议您检查其他 CLI 任务,例如generate-migrations-diff 和 migrate。我过去曾遇到过这些问题并成功解决了它们。

The way doctrine creates tables in the db is by loading the models and reading the definitions within each of these models. If the CLI is not able to load the models then the table creation will fail. Unfortunately the CLI task does not report this.

Further I would advise you to check other CLI tasks such as generate-migrations-diff and migrate. I have had issues with these in the past and have resolved them successfully.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文