que tenía una base de datos PostgreSQL existente con una tabla creada de esta manera:Cómo evitar declaraciones DROP DEFAULT con Doctrine 2 Migrations diff en la primera ejecución?
CREATE TABLE product (id SERIAL PRIMARY KEY, name VARCHAR(100) DEFAULT NULL)
En esta tabla se describe en un archivo YML Doctrine2 dentro de un proyecto Symfony2:
Acme\DemoBundle\Entity\Product:
type: entity
table: product
fields:
id:
id: true
type: integer
nullable: false
generator:
strategy: SEQUENCE
name:
type: string
length: 100
nullable: true
Cuando corro por primera vez la tarea de diferencias Doctrine Migrations, debería obtener un archivo de versiones sin datos en los métodos up
y down
. Pero lo que obtengo es esto:
// ...
class Version20120807125808 extends AbstractMigration
{
public function up(Schema $schema)
{
// this up() migration is autogenerated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "postgresql");
$this->addSql("ALTER TABLE product ALTER id DROP DEFAULT");
}
public function down(Schema $schema)
{
// this down() migration is autogenerated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "postgresql");
$this->addSql("CREATE SEQUENCE product_id_seq");
$this->addSql("SELECT setval('product_id_seq', (SELECT MAX(id) FROM product))");
$this->addSql("ALTER TABLE product ALTER id SET DEFAULT nextval('product_id_seq')");
}
}
¿Por qué se detectan diferencias? ¿Cómo puedo evitar esto? Intenté varias estrategias de secuencia sin éxito.
¡Gracias por tan valiosa respuesta! –
@VaheShadunts ¡De nada! –