#symfony #doctrine-orm #api-platform.com
#symfony — последовательность запросов API не существует #doctrine-orm #api-platform.com
Вопрос:
Я создал объект с помощью doctrine ORM и синхронизировал объект с базой данных postgres, используя следующую команду.
sudo /usr/local/bin/docker-compose exec php bin/console doctrine:schema:update --dump-sql
The following SQL statements will be executed:
CREATE SEQUENCE financial_statement_type_id_seq INCREMENT BY 1 MINVALUE 1 START 1;
CREATE SEQUENCE financial_statement_templates_fstemplate_id_seq INCREMENT BY 1 MINVALUE 1 START 1;
CREATE SEQUENCE financial_statement_templates_definition_fstemplate_definition_id_seq INCREMENT BY 1 MINVALUE 1 START 1;
CREATE TABLE financial_statement_type (id INT NOT NULL, fstype_short_code VARCHAR(9) NOT NULL, fstype_name VARCHAR(99) NOT NULL, fstype_created_by VARCHAR(9) NOT NULL, fstype_created_on TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(id));
CREATE TABLE financial_statement_templates (fstemplate_id INT NOT NULL, fstemplate_short_code VARCHAR(9) NOT NULL, fstemplate_name VARCHAR(99) NOT NULL, fstemplate_created_by VARCHAR(9) NOT NULL, fstemplate_created_on TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(fstemplate_id));
CREATE TABLE financial_statement_templates_definition (fstemplate_definition_id INT NOT NULL, fstemplate_definition_type VARCHAR(9) NOT NULL, fstemplate_definition VARCHAR(5000) NOT NULL, fstemplate_created_by VARCHAR(9) NOT NULL, fstemplate_created_on TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(fstemplate_definition_id));
Чтобы создать объект, используя страницу платформы API в браузере, я предоставил следующие данные
{
"financialStatementTypeShortCode": "BS",
"financialStatementTypeName": "BALANCE SHEET",
"financialStatementTypeCreatedBy": "000000001",
"financialStatementTypeCreatedOn": "2020-12-04T10:06:30.672Z"
}
Операция выдает ошибку (воспроизводится соответствующая часть)
"type": "https://tools.ietf.org/html/rfc2616#section-10",
"title": "An error occurred",
"detail": "An exception occurred while executing 'SELECT NEXTVAL('financial_statement_type_id_seq')':nnSQLSTATE[42P01]: Undefined table: 7 ERROR: relation "financial_statement_type_id_seq" does not existnLINE 1: SELECT NEXTVAL('financial_statement_type_id_seq')n
В сообщении говорится, что последовательность financial_statement_type_id_seq не существует. Однако обновление схемы показывает, что последовательность была создана. Есть ли что-то, чего мне не хватает? Есть ли способ решить эту проблему?
Редактировать
namespace AppEntity;
use ApiPlatformCoreAnnotationApiResource;
use DoctrineORMMapping as ORM;
use SymfonyComponentValidatorConstraints as Assert;
// use DoctrineCommonCollectionsArrayCollection; Used in the documentation but not in the sample file
/**
* FINANCIAL STATEMENT TYPE
* Describes the type of Financial Statement
* @ApiResource
* @ORMEntity
*/
class financial_statement_type
{
/**
* @var int A unique identifier for the balance sheet template
*
* @ORMId
* @ORMGeneratedValue
* @ORMColumn(type="integer")
*/
private $id;
/**
* @var string A shortcode for the financial statement type e.g. BS – Balance Sheet IS – Income Statement
*
* @ORMColumn(type="string", length=9)
* @AssertNotBlank
*/
private $fstype_ShortCode = '';
/**
* @var string A decriptive name for the financial statement
*
* @ORMColumn(type="string", length=99)
* @AssertNotBlank
*/
private $fstype_Name = '';
/**
* @var string The userid of the person who created this template
*
* @ORMColumn(type="string", length=9)
* @AssertNotBlank
*/
private $fstype_CreatedBy = '';
/**
* @var DateTimeInterface The date and time this financial statement type was created on
*
* @ORMColumn(type="datetime")
* @AssertType("DateTimeInterface")
* @AssertNotBlank
*/
private $fstype_CreatedOn = '';
public function getfinancialStatementTypeId(): int
{
return $this->fstype_Id;
}
(также содержит функции get и set — не воспроизводится здесь для краткости)
Комментарии:
1. Итак, можете ли вы также показать свои объекты, пожалуйста?
2. Обновлены сущности в исходном вопросе
3. Я запустил создание схемы, чтобы пока решить проблему.
4. Просто понял, что при изменении имени столбца идентификатора и запуске обновления схемы новые последовательности не создаются. Схема должна быть удалена и воссоздана заново.