问题描述
我一直在尝试从 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');