简体   繁体   中英

Doctrine: always tells me the database isn't in sync after using two custom mapping types

I've created two custom mapping types : one for a Money value object and one for an Email value object

Now, each time I run app/console doctrine:schema:validate Doctrine tells me the database is not in sync.

Dumping the sql with app/console doctrine:schema:update --dump-sql it wants each time to update the same fields in the same way:

ALTER TABLE invoices CHANGE total total VARCHAR(255) NOT NULL;
ALTER TABLE subscriptions CHANGE next_payment_amount next_payment_amount VARCHAR(255) NOT NULL;
ALTER TABLE stripe_charges CHANGE amount amount VARCHAR(200) NOT NULL, CHANGE receipt_email receipt_email VARCHAR(255) DEFAULT NULL;
ALTER TABLE stripe_customers CHANGE email email VARCHAR(255) DEFAULT NULL;

Each time it tries to update these tables setting them in the exact same state they already are. Is a fault of mine or is a Doctrine's one?

Here the code for the two types: MoneyType and EmailType .

GitHub/Doctrine Issue here .

Doctrine is seeing each of the columns on your database as strings but thinking you want them to be money/email so it's deciding that you need to migrate each time.

The way to sort this is by adding the requiresSQLCommentHint so that it adds some text in your column comment to show that it actually is the correct customer type. You do this by just adding..

/**
 * {@inheritdoc}
 */
public function requiresSQLCommentHint(AbstractPlatform $platform)
{
    return true;
}

.. to your custom types and Doctrine will handle the rest.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM