首页 > 解决方案 > Laravel Postgres SQLSTATE [42601]:语法错误:7 错误:“”“”或附近的零长度分隔标识符

问题描述

我正在尝试使用 laravel 播种数据,但尽管尝试将所有内容替换""''

我的代码

foreach ($groupPermissionsStructure as $groupName => $permissionStructure) {

            $group = collect($groups->where('alias', $groupName)->first());

            if ($group->isNotEmpty()) {

                $group = Group::firstOrCreate([
                    'name' => $group['name'],
                    'alias' => strtolower($group['alias']),
                    'description' => $group['description'],
                    'organization_id' => 1,
                    'status' => 1,
                ]);

                $names = explode(" ", $group['name']);

                $domain = str_replace([" ", "-", "_"], "", $groupName);

                User::firstOrCreate([
                    'first_name' => $names[0],
                    'last_name' => isset($names[1]) ? $names[1] : $names[0],
                    'email' => $domain . '@test.com',
                    'email_verified_at' => Carbon::now(),
                    'status' => config('constants.status.active'),
                    'group_id' => $group->id,
                    'password' => Hash::make($domain)
                ]);
            }

我的错误

SQLSTATE[42601]: Syntax error: 7 ERROR:  zero-length delimited identifier at or near """"
LINE 1: select * from ""."groups" where ("name" = $1 and "alias" = $...
                      ^ (SQL: select * from ""."groups" where ("name" = Super Administrator and "alias" = super_administrator and "description" = Overall system super administrator and "organization_id" = 1 and "status" = 1) and ""."groups"."deleted_at" is null limit 1)

标签: laravel

解决方案


推荐阅读