【问题标题】:Laravel 5 - SQLSTATE[22P02] - invalid text representation with postgresLaravel 5 - SQLSTATE [22P02] - postgres 的无效文本表示
【发布时间】:2015-11-26 03:59:57
【问题描述】:

错误:

SQLSTATE[22P02]:文本表示无效:7 错误:输入无效 整数的语法:“dismissnotification”(SQL:select * from “users” 其中“id”=驳回通知)

在我的 routes.php 文件中:

Route::get('user/dismissnotification/{notificationid}',array('as' => 'dismissnotification', 'uses' => 'NotificationController@dismiss'));

我认为路线的链接:

 <a href="{{ URL::route('dismissnotification',$notification->id)}}">  <i class="fa fa-times"></i> </a>

当我单击此链接时,页面被正确重定向到(例如): http://mywebsite/user/dismissnotification/222222225

我的 NotificationController 上的“dismiss”函数为空,但错误仍然存​​在。我不知道原始错误中的select * from "users" 来自哪里。

public function dismiss($notificationid) {
        //
}

我是否遗漏了一些明显的东西?如果我的函数中根本没有代码并且路线显然是正确的,那么可能导致此错误的原因是什么?

【问题讨论】:

  • 这是一个 SQL 问题。您有一个查询,其中参数具有无效的文本表示。你能追踪查询是什么以及参数是什么吗?
  • 对我来说,我使用 postgres 将我的应用程序部署在两个热点中,代码在一个中运行良好,但在另一个中运行不正常,很奇怪,本地 mysql 没有问题,有什么消息吗?

标签: php postgresql laravel syntax integer


【解决方案1】:

SQL 查询显示 Laravel 在您的路由上调用了与您预期不同的控制器方法。

select * from "users" where "id" = dismissnotification

该查询正在尝试查找 ID 与“dismissnotification”匹配的用户,因此它看起来像 UsersController@show 或 UsersController@edit 甚至可能是 UsersController@222222225,具体取决于您为 / 定义的其他路由用户。

由于 URL::route() 呈现了您所期望的路径,您的问题可能是您定义路由的顺序;但是,如果没有看到您的所有 /user 路由以及您定义它们的顺序,我无法更具体。

【讨论】:

  • 在我的情况下,这是因为我在表 id 以外的其他东西上有一个模型关系。我的修复(来自@Trip 提示)是将$this-&gt;belongsTo( Monitor::class, 'domain' ); 改为:return $this-&gt;belongsTo( Monitor::class, 'domain', 'domain' );,同时指定外部other 关系。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-07-22
  • 1970-01-01
  • 1970-01-01
  • 2023-04-09
  • 2020-10-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多