How to create dummy Drupal content with Drush and Devel

When you are developing a new Drupal website, you often need to populate it with dummy content. Manually added content is tedious and wastes time. Fortunately with just one Drush command, you can generate as much dummy content as you want.

The Devel Generate module, which comes with Devel, has some Drush commands built in to generate dummy content. If you haven't already installed the Devel module, you can install and enable it with Drush:
$ drush dl devel
$ drush en devel -y

Even though Devel Generate comes with Devel, it needs to be enabled separately. So without further ado, enable it with Drush:
$ drush en devel_generate -y

Devel Generate provides a command called generate-content. It takes two arguments, the number of nodes to create and the maximum number of comments per node.

If you want to create 20 nodes and no comments, you will use the following:
$ drush generate-content 20

You can see the nodes by going to admin/content:

If the content type has a image field, it will create a dummy image. This is what an article looks like with a dummy title, image and body content:

It is quite common for Drush commands to have an alias. An alias is a shorter version of the command and makes it easier to type. The alias for generate-content is genc. To repeat the above with the alias:
$ drush genc 20

If you want to create comments as well, add in the second argument. The following will create 20 nodes and a maximum of 10 comments per node.
$ drush genc 20 10

You can even delete nodes before creating new ones with the kill option.
$ drush genc 2 10 --kill

If you have created specific content types, you can specify a content type, so Devel Generate will generate just that type of content. To generate 20 nodes that belong to the Latest News content type:
$ drush genc 20 --types=latest_news

To generate 20 Latest News nodes with a maximum of 10 comments and delete existing content, use:
$ drush genc 20 10 --kill --types=latest_news

If you don't want to use Drush to generate the content, you can also do it the old fashioned way by going to the following path on your site: admin/config/development/generate/content.

Comments

This was a very interesting and very informative tutorial that shows "How to create dummy Drupal content with Drush and Devel". Really thank you for sharing this with us. We appreciate your effort for writing amazing tutorials like this. Regards.

Hi Blair,

Very nice write up. Didn't know about the kill switch. Very handy.

Btw, if you just run...

<code>$ drush en devel -y</code>

Drush will download the module (if it's not present already) and then enable it.

No need for the drush dl command.

Thanks, Pete.

Are field collections not supported?

Blair Wadman's picture

As far as I know, field collections are supported. There is an issue here you might want to check out: https://www.drupal.org/node/1827008

Great man. It helped me :)

That was really easy to understand, thank you a lot for sharing this post.I tried it up and it was easier than I thought it would be.

Thanks for sharing man, This helped me a lot. Thanks

Add new comment