我已经尝试执行 cli 命令 ./doctrine generate-migrations-diff 并在正确的文件夹中正确创建了一个版本文件。
消息是:generate-migrations-diff - Generated migration classes successfully from difference
然后我尝试执行另一个 cli 命令 ./doctrine migrate,我看到一条消息:migrate - 已成功迁移到版本 #1 但是当我打开类(class)时,任何修改都已完成。为什么?
这是版本 1 文件:
<?php
class Version1 extends Doctrine_Migration_Base
{
public function up()
{
$this->removeColumn('addresses', 'address_test');
}
public function down()
{
$this->addColumn('addresses', 'address_test', 'string', '', array(
'fixed' => '0',
'unsigned' => '',
'primary' => '',
'notnull' => '1',
'autoincrement' => '',
));
}
}
?>
这是 YAML。 我已经删除了字段:address_test
Addresses:
connection: doctrine
tableName: addresses
columns:
address_id:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
address:
type: string()
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
city:
type: string(150)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
code:
type: string(20)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
country_id:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
base:
type: integer(1)
fixed: false
unsigned: false
primary: false
default: '0'
notnull: true
autoincrement: false
latitude:
type: string(20)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
longitude:
type: string(20)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
customer_id:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
这是 migrate 命令生成的 BaseAddresses 类: bindComponent('地址', ' Doctrine ');
/**
* BaseAddresses
*
* This class has been auto-generated by the Doctrine ORM Framework
*
* @property integer $address_id
* @property string $address
* @property string $city
* @property string $code
* @property integer $country_id
* @property integer $base
* @property string $latitude
* @property string $longitude
* @property integer $customer_id
* @property Countries $Countries
* @property Customers $Customers
*
* @package ##PACKAGE##
* @subpackage ##SUBPACKAGE##
* @author ##NAME## <##EMAIL##>
* @version SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $
*/
abstract class BaseAddresses extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('addresses');
$this->hasColumn('address_id', 'integer', 4, array(
'type' => 'integer',
'fixed' => 0,
'unsigned' => false,
'primary' => true,
'autoincrement' => true,
'length' => '4',
));
$this->hasColumn('address', 'string', null, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => false,
'autoincrement' => false,
'length' => '',
));
$this->hasColumn('city', 'string', 150, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => false,
'autoincrement' => false,
'length' => '150',
));
$this->hasColumn('code', 'string', 20, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => false,
'autoincrement' => false,
'length' => '20',
));
$this->hasColumn('country_id', 'integer', 4, array(
'type' => 'integer',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => false,
'autoincrement' => false,
'length' => '4',
));
$this->hasColumn('base', 'integer', 1, array(
'type' => 'integer',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'default' => '0',
'notnull' => true,
'autoincrement' => false,
'length' => '1',
));
$this->hasColumn('latitude', 'string', 20, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => false,
'autoincrement' => false,
'length' => '20',
));
$this->hasColumn('longitude', 'string', 20, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => false,
'autoincrement' => false,
'length' => '20',
));
$this->hasColumn('customer_id', 'integer', 4, array(
'type' => 'integer',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
'length' => '4',
));
}
public function setUp()
{
parent::setUp();
$this->hasOne('Countries', array(
'local' => 'country_id',
'foreign' => 'country_id'));
$this->hasOne('Customers', array(
'local' => 'customer_id',
'foreign' => 'customer_id',
'onDelete' => 'CASCADE'));
}
}
在某些网站上,我读到我必须执行命令:build-all 以生成类地址的更新版本,但我收到此错误:
SQLSTATE[HY000]: General error: 1005 Can't create table 'web63db1.#sql-3e6_11d' (errno: 121). Failing Query: "ALTER TABLE addresses ADD CONSTRAINT addresses_customer_id_customers_customer_id FOREIGN KEY (customer_id) REFERENCES customers(customer_id) ON DELETE CASCADE". Failing Query: ALTER TABLE addresses ADD CONSTRAINT addresses_customer_id_customers_customer_id FOREIGN KEY (customer_id) REFERENCES customers(customer_id) ON DELETE CASCADE
我做了什么?提前致谢。
最佳答案
迁移仅用于更改您的数据库,而不是您的模型类。之后您需要构建模型类。
所以你的正常工作方式是:
关于php - Doctrine generate-migrations-diff 和 migrate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3059997/
我是RoR的新手,我正在学习MichaelHartl的教程(所以请随意更正我在您认为合适的地方使用的术语)。在第2章中,我通过运行以下行创建了一个Users表:$railsgeneratescaffoldUsername:stringemail:string$bundleexecrakedb:migrate然后,我运行了下面的代码来尝试创建一个Microposts表(但是,我拼错了没有“r”的Micropost!)...$railsgeneratescaffoldMiropostcontent:stringuser_id:integer$bundleexecrakedb:migrate
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭9年前。我来自C、php和bash背景,很容易学习,因为它们都有相同的C结构,我可以将其与我已经知道的联系起来。然后2年前我学了Python并且学得很好,Python对我来说比Ruby更容易学。然后从去年开始,我一直在尝试学习Ruby,然后是Rails,我承认,直到现在我还是学不会,讽刺的是那些打着简单易学的烙印,但是对于我这样一个老练的程序员来说,我只是无法将它
我在新的Rails应用程序(3.2.3)中运行迁移时遇到了问题。我们正在使用postrgres9.1.3和-pg(0.13.2)-当我运行rakedb:create,然后运行rakedb:migrate,我得到->1.9.3-p194(master)rakedb:migrate--trace**Invokedb:migrate(first_time)**Invokeenvironment(first_time)**Executeenvironmentrakeaborted!PG::Error:ERROR:relation"roles"doesnotexistLINE4:WHEREa
为了防止在迁移到生产站点期间出现数据库事务错误,我们遵循了https://github.com/LendingHome/zero_downtime_migrations中列出的建议。(具体由https://robots.thoughtbot.com/how-to-create-postgres-indexes-concurrently-in概述),但在特别大的表上创建索引期间,即使是索引创建的“并发”方法也会锁定表并导致该表上的任何ActiveRecord创建或更新导致各自的事务失败有PG::InFailedSqlTransaction异常。下面是我们运行Rails4.2(使用Acti
为什么rakedb:migrate运行Executedb:schema:dump我的输出全都搞砸了(显示SQL)。看起来像这样:ActiveRecord::SchemaMigrationLoad(0.5ms)SELECT"schema_migrations".*FROM"schema_migrations"(3.7ms)SELECTt2.oid::regclass::textASto_table,a1.attnameAScolumn,a2.attnameASprimary_key,c.connameASname,c.confupdtypeASon_update,c.confdeltyp
我已经通过这种方式在数据库中创建了外键:classCreateUser但忘记添加on_delete::nullify。迁移已被推送并用于生产。我想添加新的迁移,这将为此PK约束添加级联删除。如何实现? 最佳答案 您可以在下次迁移时删除和添加外键:classChangeForgeinKeyOnUsersTable 关于ruby-on-rails-添加:on_deletetoalreadyexistingforeign_keyinrailsmigration,我们在StackOverflow
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭10年前。我使用PHP的时间太长了,对它感到厌倦了。我也想学习一门新语言。我一直在使用Ruby并且喜欢它。我必须在Rails和Sinatra之间做出选择,那么您会推荐哪一个?Sinatra真的不能用来构建复杂的应用程序,它只能用于简单的应用程序吗?
我在Rails3中进行数据库迁移时遇到异常。undefinedmethod`visitor'for#编辑请查看解决方案here.在我的项目中没有出现字符串visitor所以我很困惑。这是完整的转储:$rakedb:migrate--trace**Invokedb:migrate(first_time)**Invokeenvironment(first_time)**Executeenvironment**Invokedb:load_config(first_time)**Invokerails_env(first_time)**Executerails_env**Executedb:l
好的,所以我有一个Rails应用程序,我试图在postgres数据库上运行迁移,我通常使用mysql,一切都很好,但是当我运行命令时,我得到了这个rakedb:migrate(in/Users/tamer/Sites/my_app)/Users/tamer/.rvm/gems/ruby-1.9.2-p290@my_app/gems/activerecord-3.0.3/lib/active_record/connection_adapters/postgresql_adapter.rb:487:[BUG]Segmentationfaultruby1.9.2p290(2011-07-09
我最近使用RVM从Ruby2.2.2升级到2.2.3。这搞砸了我的开发环境中的一些事情,但由于有用的错误消息,到目前为止我可以处理它。现在我想向我的数据库添加一些迁移,但遇到了这个错误:$rakedb:migrate/Users/howard/.rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in`eval':/Users/howard/.rvm/rubies/ruby-2.2.3/bin/rake:4:syntaxerror,unexpectedtSTRING_BEG,expectingkeyword_door'{'or'('(Syn