OnCollisionEnter2D error

I have been trying to get OnCollisionEnter2D and other things like it to work for a while now and I have no idea what’s going on. I looked at a class I have for Unity and I’m doing the same thing it is telling you to do in the class and I have looked at forum posts and nothing works. Here is my code:

 void OnCollisionEnter2D(Collider2D coll)
    {
        if (coll.gameObject.tag == "Hazard")
        {
            Debug.Log("Collided with the spikes.");
        }
    }

Please tell me if there’s anything wrong with that. By the way “Is kinematic” is off on my Rigidbody2D GameObject and my spikes are not triggers. I am learning Unity as I go so some help would be appreciated.

EDIT
I forgot to add the error I get for the code. When I play the game I got the error:

Script error: OnCollisionEnter2D
This message parameter has to be of type:

The parameter has to be of type “Collision2D”. Not “Collider2D”.

“Collider2D” is for triggers.

Thank you!