dbal: Problem with doctrine diff
Hi,
When i use the doctrine diff, doctrine create a file with this line :
<?php declare(strict_types = 1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20180129135625 extends AbstractMigration
{
public function up(Schema $schema)
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE address CHANGE complement complement VARCHAR(255) DEFAULT NULL');
}
public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE address CHANGE complement complement VARCHAR(255) DEFAULT \'NULL\' COLLATE utf8_unicode_ci');
}
}
I use Symfony 4, with php 7 and MariaDB from latest version.
My mapping is
App\Entity\Address:
type: entity
repositoryClass: App\Repository\AddressRepository
indexes:
uuid_index:
columns: [ uuid ]
id:
id:
type: integer
generator: {strategy: AUTO}
fields:
uuid:
type: uuid
unique: true
name:
type: string
length: 100
address:
type: string
length: 255
complement:
type: string
nullable: true
length: 255
postcode:
type: string
length: 100
city:
type: string
length: 100
deleted:
type: boolean
createdAt:
type: datetime
gedmo:
timestampable:
on: create
updatedAt:
type: datetime
gedmo:
timestampable:
on: update
when i use very verbose on my command, doctrine create this request :
CREATE TABLE address (
id INT AUTO_INCREMENT NOT NULL,
uuid CHAR(36) NOT NULL COMMENT '(DC2Type:uuid)',
name VARCHAR(100) NOT NULL,
address VARCHAR(255) NOT NULL,
complement VARCHAR(255) DEFAULT NULL,
postcode VARCHAR(100) NOT NULL,
city VARCHAR(100) NOT NULL,
deleted TINYINT(1) NOT NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
UNIQUE INDEX UNIQ_D4E6F81D17F50A6 (uuid),
INDEX uuid_index (uuid),
PRIMARY KEY(id)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB
When i use PMA to export my table :
DROP TABLE IF EXISTS `address`;
CREATE TABLE IF NOT EXISTS `address` (
`id` int(11) NOT NULL,
`uuid` char(36) COLLATE utf8_unicode_ci NOT NULL COMMENT '(DC2Type:uuid)',
`name` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`address` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`complement` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`postcode` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`city` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`deleted` tinyint(1) NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
So the problem is not on my server i think…
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 6
- Comments: 28 (7 by maintainers)
Leaving this Link for future searchers of this problem. Completely fixed my problem with
:diff
command.@bocharsky-bw Since my MariaDB version was 10.3.13 my exact value for the
server_version
wasmariadb-10.3.13
I had a similar issue where my migration always mixed up NULL with ‘NULL’ - found out that I did not set the correct server version for MariaDB in the doctrine.yaml config: https://github.com/doctrine/dbal/issues/3321#issuecomment-447642346