tinker 生成表出错?

App\Models\User::create(['name'=>'Aufree','email'=>'aufree@yousails.com','password'=>bcrypt('password')])
执行如上语句出错

Illuminate\Database\QueryException with message 'could not find driver (SQL: insert into users (name, email, password, updated_at, created_at) values (Aufree, aufree@yousails.com, $2y$10$uPKG
H.31c4DrcWDdX6JAwOEojbbBn7z04rSUtK/prSz.ZXeYSmjaC, 2018-03-21 05:25:17, 2018-03-21 05:25:17))'

《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
最佳答案

感觉像pdo 出问题了 你使用的 教程的homestead 吗 还有 这个命令 是在本地 运行的 还是 在 虚拟机里运行的

6年前 评论
讨论数量: 14

贴一下.env 的文件吧, 在这之前是否有运行 php aritrsan migrate 数据库迁移。

6年前 评论

@张志强 是的,执行了php aritrsan migrate.
.env文件内容:

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:MWdCz1sjNfycNLW6ZVErm9dyTOCra92ocp5DpMOLMq8=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=sample
DB_USERNAME=homestead
DB_PASSWORD=secret

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

6年前 评论

@张志强 不过我看数据库里面没有任何表哦。

6年前 评论

@张志强
我是执行了这一步后才执行tinker
$ php artisan make:model Models/Article -m
Model created successfully.
Created Migration: 2018_03_21_051402_create_articles_table

6年前 评论

执行 php artisan migrate 然后在执行 thinker的操作 你试下

6年前 评论

@yi丶抹浅笑
执行出错。
Administrator@PPT05-20170705H MINGW64 ~/code/sample (modeling-users)
$ php artisan migrate

In Connection.php line 664:

could not find driver (SQL: select * from information_schema.tables where table_schema = sample and table_name = migrations)

In Connector.php line 67:

could not find driver

6年前 评论

感觉像pdo 出问题了 你使用的 教程的homestead 吗 还有 这个命令 是在本地 运行的 还是 在 虚拟机里运行的

6年前 评论

@yi丶抹浅笑
@张志强
多谢,我找到原因了,
我当前用的是GIT BASH客户端,在WINDOWS系统下面,因为没有执行vagrant ssh,但是GIT BASH的命令行与Linux一样,所以我没有发现,实际都是在本地执行的,没有连接到homestead虚拟机里面执行,因此出现了上述问题。

6年前 评论

@yi丶抹浅笑
vagrant@homestead:~/Code/sample$ php artisan tinker
Psy Shell v0.8.17 (PHP 7.2.2-1+ubuntu16.04.1+deb.sury.org+1 — cli) by Justin Hileman

App\Models\User::create(['name'=>'Aufree','email'=>'aufree@yousails.com','password'=>bcrypt('password')])
Illuminate\Database\QueryException with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'sample.users' doesn't exist (SQL: insert into users (name, email, password, updated_at, created_at) values (Aufree, aufree@yousails.com, $2y$10$b51PDxFfvPwQP8qW98/zQu4EYzw7xp/WioB.lRUE2XSMgdD7D90he, 2018-03-21 06:56:31, 2018-03-21 06:56:31))'
最新的问题是没有表,

6年前 评论

@fufeiyu112 没有表 执行 php artisan migrate

6年前 评论

@yi丶抹浅笑
OK了,THKS
vagrant@homestead:~/Code/sample$ php artisan migrate
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_000000_create_users_table
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated: 2014_10_12_100000_create_password_resets_table
vagrant@homestead:~/Code/sample$ php artisan tinker
Psy Shell v0.8.17 (PHP 7.2.2-1+ubuntu16.04.1+deb.sury.org+1 — cli) by Justin Hileman

App\Models\User::create(['name'=>'Aufree','email'=>'aufree@yousails.com','password'=>bcrypt('password')])
=> App\Models\User {#765
name: "Aufree",
email: "aufree@yousails.com",
updated_at: "2018-03-21 07:06:38",
created_at: "2018-03-21 07:06:38",
id: 1,
}

6年前 评论

由报错信息可以知道是 PDO 的锅 ,应该是 PDO 驱动安装问题,如果是在 Homestead 环境下,PDO 驱动肯定是安装好的,由此可以推断是运行环境出现问题,典型的马后炮分析,哈哈

5年前 评论

这个应该是没有执行数据库迁移,执行数据库迁移后在数据库中就有users这个表,再在tinker环境执行创建用户,就没有问题,我也遇到这个问题了的

4年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!