我正在创建一个web应用程序,它的后端是laravelvoyager。从那里,我可以毫无问题地将数据操纵到数据库中。现在我通过运行 php artisan make:command
将向数据库中插入数据
这是我的密码:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use DateTime;
use DB;
use App\CronTest;
class SampleCron extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'sample:cron';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Sample CRON';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$datetime = new DateTime();
$timestamp = $datetime->format('Y-m-d H:i:s');
// DB::table('cron_tests')->insert([
// 'name' => $timestamp
// ]);
CronTest::create(['name' => $timestamp]);
}
}
这是我的crontest.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class CronTest extends Model
{
protected $fillable = ["name"];
}
所以每次我都会跑 php artisan sample:cron
它将插入一个 $timestamp
到数据库。自从我用docker运行这个项目以来,我的本地机器就没有问题了。但是在amazonwebservice(aws)中的dev服务器中,为了安全起见,我在rds中分离了db。现在发生的是 php artisan sample:cron
命令将返回错误
这就是错误
In Connection.php line 664:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydb.cro
n_tests' doesn't exist (SQL: insert into `cron_tests` (`name`, `updated_at`
, `created_at`) values (2018-11-14 06:31:19, 2018-11-14 06:31:19, 2018-11-1
4 06:31:19))
In PDOConnection.php line 79:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydb.cro
n_tests' doesn't exist
In PDOConnection.php line 77:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydb.cro
n_tests' doesn't exist
我使用mysql工作台检查了rds数据库,并尝试运行sql查询 mydb.cron_tests
它就在那里。实际上,我复制了本地数据库并将其导入rds。
有人知道这个错误是怎么发生的吗?谢谢您!
暂无答案!
目前还没有任何答案,快来回答吧!