Php 根据原则进行迁移时出错

Php 根据原则进行迁移时出错,php,sql-server,symfony,doctrine,symfony4,Php,Sql Server,Symfony,Doctrine,Symfony4,我正试图通过对刚创建的实体进行迁移,将表创建到sql server中,但在执行查询时会引发异常: SQLSTATE [42000, 15135]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Object is invalid. Extended properties are not permitted on 'dbo.[user].roles', or the object does not exist. 通过使用maker b

我正试图通过对刚创建的实体进行迁移,将表创建到sql server中,但在执行查询时会引发异常:

SQLSTATE [42000, 15135]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Object is invalid. Extended properties are not permitted on 'dbo.[user].roles', or the object does not exist.
通过使用maker bundle,我创建了一个新的用户实体

我进行了迁移:

$ php bin/console doctrine:migrations:migrate

                    Application Migrations


WARNING! You are about to execute a database migration that could result in schema changes and data loss. Are you sure you wish to continue? (y/n)y
Migrating up to 20181121121145 from 0

  ++ migrating 20181121121145

     -> CREATE TABLE [user] (id INT IDENTITY NOT NULL, username NVARCHAR(180) NOT NULL, roles VARCHAR(MAX) NOT NULL, password NVARCHAR(255) NOT NULL, email NVARCHAR(255) NOT NULL, PRIMARY KEY (id))
     -> CREATE UNIQUE INDEX UNIQ_8D93D649F85E0677 ON [user] (username) WHERE username IS NOT NULL
     -> EXEC sp_addextendedproperty N'MS_Description', N'(DC2Type:json)', N'SCHEMA', 'dbo', N'TABLE', '[user]', N'COLUMN', roles
Migration 20181121121145 failed during Execution. Error An exception occurred while executing 'EXEC sp_addextendedproperty N'MS_Description', N'(DC2Type:json)', N'SCHEMA', 'dbo', N'TABLE', '[user]', N'COLUMN', roles':

SQLSTATE [42000, 15135]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Object is invalid. Extended properties are not permitted on 'dbo.[user].roles', or the object does not exist.

In DBALException.php line 187:

  An exception occurred while executing 'EXEC sp_addextendedproperty N'MS_Description', N'(DC2Type:json)', N'SCHEMA', '
  dbo', N'TABLE', '[user]', N'COLUMN', roles':

  SQLSTATE [42000, 15135]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Object is invalid. Extended properties
   are not permitted on 'dbo.[user].roles', or the object does not exist.


In SQLSrvException.php line 57:

  SQLSTATE [42000, 15135]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Object is invalid. Extended properties
   are not permitted on 'dbo.[user].roles', or the object does not exist.


doctrine:migrations:migrate [--write-sql [WRITE-SQL]] [--dry-run] [--query-time] [--allow-no-migration] [--configuration [CONFIGURATION]] [--db-configuration [DB-CONFIGURATION]] [--db DB] [--em EM] [--shard SHARD] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command> [<version>]
$php bin/console make:迁移

  Success!


 Next: Review the new migration "src/Migrations/Version20181121121145.php"
 Then: Run the migration with php bin/console doctrine:migrations:migrate
 See https://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html
然后,在迁移时:

$ php bin/console doctrine:migrations:migrate

                    Application Migrations


WARNING! You are about to execute a database migration that could result in schema changes and data loss. Are you sure you wish to continue? (y/n)y
Migrating up to 20181121121145 from 0

  ++ migrating 20181121121145

     -> CREATE TABLE [user] (id INT IDENTITY NOT NULL, username NVARCHAR(180) NOT NULL, roles VARCHAR(MAX) NOT NULL, password NVARCHAR(255) NOT NULL, email NVARCHAR(255) NOT NULL, PRIMARY KEY (id))
     -> CREATE UNIQUE INDEX UNIQ_8D93D649F85E0677 ON [user] (username) WHERE username IS NOT NULL
     -> EXEC sp_addextendedproperty N'MS_Description', N'(DC2Type:json)', N'SCHEMA', 'dbo', N'TABLE', '[user]', N'COLUMN', roles
Migration 20181121121145 failed during Execution. Error An exception occurred while executing 'EXEC sp_addextendedproperty N'MS_Description', N'(DC2Type:json)', N'SCHEMA', 'dbo', N'TABLE', '[user]', N'COLUMN', roles':

SQLSTATE [42000, 15135]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Object is invalid. Extended properties are not permitted on 'dbo.[user].roles', or the object does not exist.

In DBALException.php line 187:

  An exception occurred while executing 'EXEC sp_addextendedproperty N'MS_Description', N'(DC2Type:json)', N'SCHEMA', '
  dbo', N'TABLE', '[user]', N'COLUMN', roles':

  SQLSTATE [42000, 15135]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Object is invalid. Extended properties
   are not permitted on 'dbo.[user].roles', or the object does not exist.


In SQLSrvException.php line 57:

  SQLSTATE [42000, 15135]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Object is invalid. Extended properties
   are not permitted on 'dbo.[user].roles', or the object does not exist.


doctrine:migrations:migrate [--write-sql [WRITE-SQL]] [--dry-run] [--query-time] [--allow-no-migration] [--configuration [CONFIGURATION]] [--db-configuration [DB-CONFIGURATION]] [--db DB] [--em EM] [--shard SHARD] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command> [<version>]
不显示用户而显示[user]

最终解决方案
似乎“user”是一个保留字,因此我将该类重构为另一个名称,它从头到尾都运行良好

您的代码应该如下所示:

EXEC sp_addextendedproperty N'MS_Description', N'(DC2Type:json)', N'SCHEMA', 'dbo', N'TABLE', 'user', N'COLUMN', 'roles'

错误告诉您对象“dbo.[user].roles”不存在,实际上您的对象是没有括号的“dbo..user.roles”,因此您应该使用
'user'
作为表的参数,而不是
'[user]'
问题是“user”是sql server中的保留字,因此,我将该类重构为一个不同的名称,它从头到尾都运行得很好

我按照问题底部的解释做了,它运行得很好。感谢@sepupic>>>有人能解释一下为什么我使用maker bundle进行迁移时,下面的查询是:din not show user而不是[user]?现在,当我尝试将数据插入它抛出的表中时:使用参数[“felipito”,“[]”执行“insert into user(username,roles,password,email)值(?,,,,,?)时发生异常“canelo123”fpcanelo@ati.cu“]:SQLSTATE[42000156]:[Microsoft][ODBC驱动程序17 for SQL Server][SQL Server]关键字“user”附近的语法不正确。无法准备SQLSTATE[420008180]:[Microsoft][ODBC驱动程序17 for SQL Server][SQL Server]语句。也许给出的解决方案与此有关@sepupicAnd对于INSERT,必须在括号中包含表名,因为它是关键字:INSERT INTO dbo。[用户]。。。
EXEC sp_addextendedproperty N'MS_Description', N'(DC2Type:json)', N'SCHEMA', 'dbo', N'TABLE', 'user', N'COLUMN', 'roles'