The invention relates to a preparation method of a 5-HT1F agonist compound. The preparation method of the 5-HT1F agonist compound comprises the steps that 2,3-butanedione and 2-halogenated acrylonitrile are subjected to 1,4-addition reaction to obtain 2-halogenated-5,6-dioxo n-heptanoic nitrile, then the 2-halogenated-5,6-dioxo n-heptanoic nitrile and ammonia are subjected to pyridine cyclizationand amino protection to obtain 2-disubstituted methylamino-6-acetyl pyridine, then 2-disubstituted methylamino-6-(1-methyl piperidine-4-base)formyl group piperidine is prepared through hydroxyethylation, sulfonic acid esterification and methylamine condensation reaction, and then the 5-HT1F agonist compound Lasmiditan is obtained through deprotection reaction and 2,4,6-trifluoro-benzoyl chloride amidation. The raw materials of the preparation method of the 5-HT1F agonist compound are easy to get, ultralow temperature reaction is avoided, the operation is simple and convenient, the cost is low,and industrial production of Lasmiditan is easy.