如何使用laravel 5.8正确配置sqlite数据库连接

时间:2019-07-16 07:01:21

标签: laravel sqlite

问题是我无法迁移到sqlite数据库,并且已经尝试搜索一些相关的问题而没有运气。但是,当创建新的laravel应用并按照我在以下步骤中所述的配置进行配置时,不会遇到任何问题,并且将成功迁移数据库架构。

我尝试过:

php artisan config:clear - issue still exist.

composer du -o - issue still exist

php artisan migrate - still nothing happens

这是我在.env中的配置:

DB_CONNECTION=sqlite
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=root

这是我的database.php配置:

'connections' => [

    'sqlite' => [
        'driver' => 'sqlite',
        'url' => env('DATABASE_URL'),
        'database' => database_path('database.sqlite'),
        'prefix' => '',
       'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
    ],

database migrations

这里的产品迁移:

public function up()
{
    Schema::create('products', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->integer('user_id')->unsigned();
        $table->integer('category_id')->unsigned()->nullable();
        $table->integer('supplier_id')->unsigned()->nullable();
        $table->integer('company_id')->unsigned()->nullable();
        $table->string('barcode')->unique()->nullable();
        $table->string('name')->nullable();
        $table->string('unit')->nullable();
        $table->text('description')->nullable();
        $table->string('avatar')->nullable();
        $table->double('purchase_price')->default(0.0);
        $table->double('selling_price')->default(0.0);
        $table->double('supply_price')->default(0.0);
        $table->double('taxation')->default(0);
        $table->tinyInteger('stock_limit')->default(1);
        $table->integer('quantity')->default(0); // This will be updated when adding and removing quantity of the product and should matched in inventory 
        $table->timestamp('expiration')->nullable();
        $table->string('type')->default('stock'); // consignment or stock
        $table->string('attr')->nullable();
        $table->timestamps();
    });
}

我使用以下命令创建了空的database.sqlite:

touch database\database.sqlite

这是尝试运行php artisan migration时的输出:

SQLSTATE[HY000]: General error: 1 no such table: products (SQL: select count(*) as aggregate from "products" where quantity <= stock_limit)
In PDOConnection.php line 63:
SQLSTATE[HY000]: General error: 1 no such table: products 
In PDOConnection.php line 61:
  SQLSTATE[HY000]: General error: 1 no such table: products 

0 个答案:

没有答案