我有一个带有 mongodb 的网络应用程序,使用 jenssegers 包。
由于我使用的是 mongodb,我需要创建任何迁移表吗?Jenssegers 数据库驱动程序还具有(有限的)模式生成器支持
Schema::create('users', function($collection)
{
$collection->index('name');
$collection->unique('email');
});
Run Code Online (Sandbox Code Playgroud)
我找到了两个不同的“答案”。这家伙正在使用模式生成器
Mulkave 的回答是:
问:“当我运行命令“php artisan migrate”时,我收到以下错误,因为迁移表被创建到 mongodb 数据库中:”
答:“您可能误解了 MongoDB 作为文档数据库的目的,您不需要在基于文档的数据库中进行迁移,这就是它们的优点。它们具有动态模式,因此您所要做的就是保存您的模型,无论它们具有什么属性,这意味着您必须收紧应用程序的业务逻辑,以确保模型按照您的预期保存。”
那么,我需要迁移表吗?谢谢!
我需要帮助。
我有这些表:用户、购买和编解码器。我有一个多对多的关系:buys,codecs,buy_codec
表
Schema::create('codecs', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->timestamps();
});
Schema::create('buys', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->string('name');
});
Schema::create('buy_codec', function (Blueprint $table) {
$table->increments('id');
$table->integer('buy_id')->unsigned();
$table->foreign('buy_id')->references('id')->on('buys')->onDelete('cascade');
$table->integer('codec_id')->unsigned();
$table->foreign('codec_id')->references('id')->on('codecs')->onDelete('cascade');
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)
楷模
class Codec extends Model
{
protected $guarded = ['id'];
public function buy() {
return $this->belongsToMany('App\Buy');
}
}
class Buy extends Model
{
protected $guarded = ['id'];
public function codec() {
return $this->belongsToMany('App\Codec');
}
}
class User extends Authenticatable
{
public function buy() {
return $this->hasMany('App\Buy'); …Run Code Online (Sandbox Code Playgroud) 我运行phpunit时出现此错误
错误:调用未定义的方法测试\ Feature\ViewConcertListingTest :: see()
这是我的代码:
class ViewConcertListingTest扩展TestCase {使用DatabaseMigrations;
/** @test */
public function user_can_view_a_concert_listing()
{
// Arrange
// Create a concert
$concert = Concert::create([
'title' => 'The Red Chord',
'subtitle' => 'with Animosity and Lethargy',
'date' => Carbon::parse('December 13, 2016 8:00pm'),
'ticket_price' => 3250,
'venue' => 'The Mosh Pit',
'venue_address' => '123 Example Lane',
'city' => 'Laraville',
'state' => 'ON',
'zip' => '17916',
'additional_information' => 'For tickets, call (555) 555-5555'
]);
// Act
// View the concert listing
$this->get('/concerts/' …Run Code Online (Sandbox Code Playgroud) 我想在我的数据库中存储1个带有4位小数的数字.
如果我使用浮点数我只能添加2位小数
$table->float('sell');
Run Code Online (Sandbox Code Playgroud)
如果我尝试使用小数我会得到一个错误
$table->decimal('sell', 1, 4);
Run Code Online (Sandbox Code Playgroud)
第一个数字必须大于或等于第二个数字.
SQLSTATE[42000]: Syntax error or access violation: 1427 For float(M,D), double(M,D) or decimal(M,D), M must be >= D (column '
Run Code Online (Sandbox Code Playgroud)
卖').(SQL:create table customers(idint unsigned not null auto_increment primary key,selldecimal(1,4)not null,
created_attimestamp null,updated_attimestamp null)default character set utf8 collate utf8_unicode_ci)
有帮助吗?
谢谢
laravel ×4
laravel-5 ×3
eloquent ×2
laravel-5.2 ×2
laravel-5.5 ×1
many-to-many ×1
mongodb ×1
php ×1
phpunit ×1
sql ×1