Doctrine generate-migrations-diff and migrate

I tried to run the cli./doctrine generate-migrations-diff command and the version file was correctly created in the right folder.

Message: generate-migrations-diff - generated migration classes successfully out of difference

Then I try to run another cli./doctrine migrate command and the message appears: migrate - successfully migrated to version # 1 , but when I open the class, all the changes were made. Why?

This is version1 file:

<?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' => '',
         ));
}
}

?>

This is YAML. I deleted the field: 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

This is the BaseAddresses class generated by the migrate command : bindComponent (Addresses, 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

? .

+3
2

, . .

, :

  • schema.yml
  • (generate-migrations-diff)
  • (migrate), .
  • (-)
+6

, :

  • schema.yml
  • (doctrine: generate-migrations-diff) (: )
  • (doctrine: migrate) ( ).
  • . (doctrine: build --all-classes OR doctrine: build-model and doctrine: build-forms and doctrine: build-filters) (: , .)

, - . (.. - , ), , . db, live db . .

, "doctrine: generate-migrations-diff" schema.yml .

schema.yml . 3 4 ( ), .

+1

Source: https://habr.com/ru/post/1750449/


All Articles