0

I'm updating schema in a Symfony app. This app was not written by me, so I'm groping the dark as it were.

I have validated the schema with php bin/console doctrine:schema:validate, and get an OK, the mappings are correct. But the database schema is not in sync (I'm actually starting with an empty database...)

Then I run bin/console doctrine:schema:update --force, and get the following error:

SQLSTATE[22023]: Invalid parameter value: 7 ERROR: NUMERIC scale 10 must be between 0 and precision 2

LINE 1: ...ULL, application_id VARCHAR(255) NOT NULL, amount NUMERIC(2,...

Within the ServiceFee class:

/**
 * @ORM\Column(type="decimal", precision=2, scale=10)
 */
private $amount;

And the relevant SQL command (retrieved with bin/console doctrine:schema:update --dump-sql):

CREATE TABLE service_fees (
    id INT NOT NULL,
    created TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
    modified TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
    uuid VARCHAR(255) NOT NULL,
    organization_id VARCHAR(255) NOT NULL,
    application_id VARCHAR(255) NOT NULL,
    amount NUMERIC(2, 10) NOT NULL,
    charged BOOLEAN NOT NULL,
    payment_method_type VARCHAR(255) NOT NULL,
    transaction_number VARCHAR(255) NOT NULL,
    removed BOOLEAN NOT NULL,
    PRIMARY KEY(id)
);
CREATE UNIQUE INDEX unique_uuid ON service_fees (uuid);

After executing the command above, I start getting a new error, but I'm not sure if this is a result of an incomplete schema update:

SQLSTATE[42703]: Undefined column: 7 ERROR: column "min_value" does not exist

LINE 1: SELECT min_value, increment_by FROM "translations_id_seq"

1 Answer 1

1

Your definition of the NUMERIC column is wrong. From PostgreSQL documentation:

The scale of a numeric is the count of decimal digits in the fractional part, to the right of the decimal point. The precision of a numeric is the total count of significant digits in the whole number, that is, the number of digits to both sides of the decimal point. So the number 23.5141 has a precision of 6 and a scale of 4. Integers can be considered to have a scale of zero.

Source: https://www.postgresql.org/docs/10/static/datatype-numeric.html#DATATYPE-NUMERIC-DECIMAL

Sign up to request clarification or add additional context in comments.

3 Comments

This is correct, I believe the original coder reversed the precision and scale. In other words, they wanted to allow numbers like 11111111.99, NUMERIC(10, 2), instead of the other way. Side note, I think the documentation paragraph should be reversed to reflect the argument order.
Yes, it would be a lot more intuitive to talk about the precision first, and then about the scale. Anyway, Doctrine could raise a warning in your case, it would save you some time :)
I submitted a request to change the docs to the postgres doc site. Thanks for your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.