How to create a new Entry model in Craft 3? I want to create a new entry for a section named 'drinks'(having section id= 6). The namespace of the file having this code is namespace putyourlightson\userguide\controllers;.I copied this code from StackExchange. My first line is getting an error(Class 'Craft\EntryModel' not found).

$entry = new \Craft\EntryModel();

$attributes = [
  'section'   =&gt; $yourSectionId,
  'entryType' =&gt; $yourEntryTypeId,
  'field1'    =&gt; 'foo',
  'field2'    =&gt; 'bar'
];

$entry-&gt;getContent()-&gt;setAttributes($attributes);

craft()-&gt;entries()-&gt;saveEntry($entry);


How should you import it?
Just so there's an answer here. OP was using Craft 2 code in a Craft 3 environment.

The code should be something like this in Craft 3:

$entry = new Entry();
$entry-&gt;sectionId = $yourSectionId;
$entry-&gt;typeId = $yourEntryTypeId;
$entry-&gt;authorId = $yourAuthorId;
$entry-&gt;enabled = true;
$entry-&gt;title = "Foo";
$entry-&gt;setFieldValues([
    'field1' =&gt; "Foo",
    'field2' =&gt; "Bar",
]);
$success = Craft::$app-&gt;elements-&gt;saveElement($entry);
if (!$success) {
    Craft::error('Couldn’t save the entry "'.$entry-&gt;title.'"', __METHOD__);
}