• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 2.0 Creating a thread post via code?


Well-known member
I'm trying to create a thread post using a code and I get this error:
MySQL query error [1364]: Field 'position' doesn't have a default value in src/XF/Db/AbstractStatement.php at line 183
I use this code:
$post = $this->em()->create('XF:Post');
$post->thread_id = $id;
$post->user_id = $userId;
$post->username = $username;
$post->message = $message;
Is there a better way?