Laravel中的数据库种子是什么? [英] What is database seeding in Laravel?

查看:172
本文介绍了Laravel中的数据库种子是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Laravel框架,最近我被告知有一个名为database seeding的东西会为我们的测试生成伪造的数据集.我的理解正确吗?

I use Laravel framework and I have recently been informed that there is something named database seeding which produces a fake dataset for our tests. Is my understanding correct?

这很奇怪.怎么运行的?如何知道我在数据库的X列中需要哪种类型的数据?以及它是如何产生的?

Well that's pretty much odd. How it works? How it knows which type of data do I need in X column of database? And how it generates it?

此外,我不能为真实的数据集(类似于导出)作种子吗?您知道的,我不太会说英语,这就是为什么我无法理解数据库领域 seed 的概念.

Also, Can't I make a seed of my real dataset (something like an export)? You know, I don't know English very well, that's why I cannot understand the concept of seed in database field.

推荐答案

通常,您使用的是 faker 创建虚假数据(具有关系等),用于开发和开发测试您的应用.

Usually you're using model Factories and faker to create fake data (with relations etc) for developing and testing your app.

如果要播种真实数据,只需使用命令导入转储.或者,如果您的数据类似于带有国家/地区的表格,则创建种子器,以在不使用伪造者或模型工厂的情况下插入真实数据.

If you want to seed real data, just use commands to import dump. Or, if your data is something like table with countries, create seeder which inserts the real data without using faker or model factory.

此外,您可以使用某些包从真实数据中创建种子.

Also, you can use some package to create seeder from real data.

您可能需要阅读有关播种的文档.

这篇关于Laravel中的数据库种子是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆