SQLSTATE[42804] 尝试 Heroku 运行 php artisan migrate 时出错

问题描述

我一直在尝试从 AWS Cloud9 sqlSTATE[42804]: Datatype mismatch: 7 ERROR: column "administered" cannot be cast automatically to type smallint HINT: You might need to specify "USING administered::smallint" 没有任何成功。我该如何解决这个问题?如果有人能帮助我,我将不胜感激。非常感谢!


我收到三个错误,所有这些错误都是在说

<?PHP

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class ChangeFilariasisMedicationsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('filariasis_medications',function (Blueprint $table) {
            $table->dropColumn('administered');            
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('filariasis_medications',function (Blueprint $table) {
            $table->smallInteger ('administered');
        });
    }
}

有问题的迁移文件如下:

<?PHP

namespace App;

use Illuminate\Database\Eloquent\Model;

 // 追加
use App\AdministeredDate;
use App\User;
use Illuminate\Notifications\Notifiable; 
use App\Notifications\ReminderMail; 

class FilariasisMedication extends Model
{
    protected $fillable = [
      'start_date','number_of_times','counter','administered'
    ];
    
    protected $dates = [
      'start_date',];
    
    use Notifiable;

  
    /**
     * この投薬スケジュールを所有するユーザ(Userモデルとの関係を定義)
     */
    public function medication_user()
    {
      return $this->belongsTo(User::class);
    }
    
    /**
     * この投薬スケジュールに属する投薬確定日(AdministeredDateモデルとの関係を定義)
     */
    public function administered_date()
    {
      return $this->hasMany(AdministeredDate::class);
    }
    
}

这是相关模型。

template <typename C>
static yes& f(typename std::enable_if<
    std::is_same<decltype(static_cast<typename C::const_iterator(C::*)() const>(&C::begin)),typename C::const_iterator(C::*)() const>::value>::type*);

filariasis_medications 表的当前描述: MysqL> 描述 filariasis_medications; enter image description here

解决方法

您在迁移中的括号前放置了一个空格,然后将其删除。将 $table->smallInteger ('administered'); 更改为 $table->smallInteger('administered');

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...