I'm trying to create a new entry from within the database. The section is defined in craft_sections, and the entries for craft_elements, and craft_entries seem correct after the script is run, but no entries are displayed in the UI.
1 Answer
If you really, really want to create an entry from within the database (you must have a VERY good reason to do so), then you should create a row in:
- entries
- elements
- elements_sites
- content
If you'd like the easier path, use Content migrations. Create a migration, and then add something like:
// Create the entry
$myNewEntry = new craft\elements\Entry();
$myNewEntry->setFieldValues([
'title' => 'My new entry',
'myCustomFieldHandle' => 'Look, I can even set a custom field!',
'myCustomCategoryFieldHandle' => [$categoryILookedUp->id],
]);
// Save the entry. Everything else will be handled for you by Craft's API.
Craft::$app->getElements()->saveElement($myNewEntry);
-
The Craft 2 Content migration docs: docs.craftcms.com/v2/plugins/migrations.html– poniesCommented Mar 9, 2020 at 22:12