将数据插入数据库中的Laravel命令错误

时间:2018-11-14 06:47:05

标签: php mysql laravel amazon-web-services

我正在创建一个以Laravel Voyager作为后端的Web应用程序。从那里,我可以毫无问题地处理到数据库的数据。现在,我通过运行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运行该项目以来,本地计算机就没有问题。但是出于安全目的,在Amazon Web Service(AWS)中的开发服务器中,我在RDS中分离了数据库。现在发生的是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 Workbench检查了我的RDS数据库,并尝试运行sql查询mydb.cron_tests,它就在那里。我实际上是在本地复制数据库并将其导入RDS。

有人知道这个错误是怎么发生的吗?谢谢!

0 个答案:

没有答案